zgabi
zgabi

Reputation: 414

How to choose target framework from Nuget package

I'm using a NuGet package which contains the assemblies for 2 target frameworks: net45 and netstandard1.5

My project is targeting net471 (so compatible with netstandard1.5). When I add the package, it copies the dll from net45 folder. How to force NuGet to use the dll from the standard folder?

The problem with the net45 version is that it needs an older version of a dependency package, the standard dll has no dependency.

Upvotes: 16

Views: 19282

Answers (1)

Leo Liu
Leo Liu

Reputation: 76760

How to choose target framework from Nuget package

According to the official document Matching assembly versions and the target framework in a project:

When NuGet installs a package that has multiple assembly versions, it tries to match the framework name of the assembly with the target framework of the project.

So, just as Matt said: "NuGet will use the assembly that is the closest match. More specific target framework wins.", NuGet will install the .net framework assembly to your .net framework project.

To resolve this issue, you can use Matt suggestion, directly reference the .NET Standard assembly yourself in the project or you can download that nuget package manually, set it to the local feed, open it with NuGet Package Explorer, delete the folder net45 under the lib folder, install that package from local feed, then nuget will use the dll from the standard folder.

Hope this helps.

Upvotes: 12

Related Questions