Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 758
Stefan Steiger Avatar asked Mar 03 '11 12:03

Stefan Steiger


1 Answers

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>
like image 101
Frederik Gheysels Avatar answered Sep 24 '22 13:09

Frederik Gheysels