Search code examples
nuget.net-3.5.net-standard.net-4.6.1

Multi Framework Nuget Installing Incorrect Framework


I have created a nuget which targets both .Net 3.5 and Net Standard 2.0. When I install the nuget on a .Net 3.5 project, the correct version of the nuget is installed. However, when I try to install the same nuget on a .Net 4.6.1 project, the net35 version is installed, instead of the Net Standard 2.0. I thought that .Net 4.6.1 is compatible with Net Standard 2.0 (according to the official microsoft documentation: https://learn.microsoft.com/en-us/dotnet/standard/net-standard).

Am I missing something, or is the nuget packaged incorrectly?


Solution

  • NuGet does not work like that. NuGet uses the most specific target framework for a project that it can find. Since there is an assembly in the NuGet package that targets .NET Framework it will use that assembly not the .NET Standard assembly for a project that targets the .NET Framework.

    If the NuGet package did not have a lib/net35 folder then the .NET Standard 2.0 assembly would be used by the .NET Framework 4.6.1 project if a recent version of NuGet is used.

    If you want a different assembly to be used for .NET 4.6.1 projects then you would need to have an assembly in a lib/net461 folder in the NuGet package.