I am currently in the process of migrating a library project to support .NET Standard 1.1 using Visual Studio 2017.
I was hoping to release the project as a single NuGet package that could target both .NET Framework 4.5+ and .NET Core, UWP, etc.
However, when I try to install the resulting package in .NET Framework projects, a huge list of package dependencies is generated containing all the packages defined in .NET standard (see below):
I understand that these are all the assemblies defined as part of the .NET Standard 1.1 specification. However, my specific project actually requires only a tiny subset of them, and this dependency list will be extremely confusing for anyone installing the package in their projects.
I tried to follow the answer to a similar question where the recommendation was to change the project specification to reference only the exact dependencies required by the project.
However, the answer was in the context of the old project.json format, which has now been superseded by the new .csproj format in VS 2017. I tried to remove the dependency on the .NET Standard 1.1 metapackage by removing the <TargetFramework>
directive but I only managed to break the build and could not find any way to specifically add only the dependencies that were needed.
The promise of moving libraries to .NET Standard for maximum platform compatibility is extremely appealing, but what is the recommended way to structure dependencies such that projects targeting the "classic" .NET Framework do not find their projects "polluted" by all these dependencies?
From Visual Studio, select Tools > NuGet Package Manager > Package Manager Console. After the Package Manager Console pane opens, verify that the Default project drop-down list shows the project in which you want to install the package. If you have a single project in the solution, it's preselected.
Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.
Change <TargetFramework>
to <TargetFrameworks>
and add ;net45
to it. You still get a single NuGet package output but now it will only pull in the extra dependencies if you are targeting a .NET core app (which will have the dependencies already).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With