Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to target multiple framework in nuget?

Tags:

I created a library that uses: generics, extension methods and Func delegate. Func delegate is most new feature to .NET (version 3.5) in the library. When I published it to nuget, the project was targeting the .NET version 4.5.2 but when I tried to install it to a project that target version 4.5, it failed.

How to ensure that the package will be installed on any project that targets .NET 3.5 and later versions, should I change the target framework in the library to 3.5 or I should use the directory convention, and create separate dll for every framework, explained here:

Supporting multiple .NET framework versions

like image 820
mshwf Avatar asked Feb 10 '17 08:02

mshwf


People also ask

How do I target multiple net frameworks?

To target multiple frameworks, change <TargetFramework> to plural <TargetFrameworks> and include monikers for different frameworks you want to target separated by ; . Here, we will support two more frameworks . NET Framework 4.0 & 4.6. So include net40 and net46 monikers respectively as shown below.

How do I check my NuGet target framework?

You can download the . nupkg file (https://www.nuget.org/packages > Download ) then unzip it. In the file you can find references to PlatformToolset, ToolsVersion which I was able to use to look up the specific version of the compiler.


1 Answers

Target the package for 3.5 which means the lib folder should be like this.

lib\net35

If a package targets net35, it can be installed in any project that targets .NET 3.5 or above.

like image 187
Mathivanan KP Avatar answered Sep 24 '22 10:09

Mathivanan KP