Stefan Steiger
Stefan Steiger

Reputation: 82406

C#: Load referenced assembly based on framework version?

Is it possible to load a referenced assembly only if the .NET Framework version is lesser than a specific number ?

I'm using a selfmade LINQ library on .NET 2.0, but if the framework is 3.5+, it should use the M$ LINQ library, and ignore the selfmade one.

Edit:
Here's my library:
http://linq4you.codeplex.com/

Upvotes: 5

Views: 684

Answers (1)

Frederik Gheysels
Frederik Gheysels

Reputation: 56984

Yes, you can do that by modifying your project file.

Open your csproj file in a text-editor, and find the line in the project file that describes the dependency that you want to conditionally load, and make sure that it looks like this, for instance:

<Reference Include="LinqBridge" Condition="$(TargetFrameworkVersion)=='v2.0'">
  <HintPath>..\..\..\DevSupport\Lib\LinqBridge\LinqBridge.dll</HintPath>
  <Private>True</Private>
</Reference>

Upvotes: 6

Related Questions