Reducing dependencies for the .NET Standard class library?

I have converted some of my class libraries to .NET Standard with Visual Studio 2017.

It was easy, add the .NET Standard class library project instead of the original project and add all the files there. The .csproj file even looks like a nuspec file with package information, etc. Inside the project settings, the checkbox “Create NuGet package at build” was checked, which I checked. Easy peasy.

However, users of the .NET Framework of my class library now get a lot of dependencies, I counted at least 20 other nuget packages that were added, most of which were completely unnecessary for my library. In other words, it was easy "easy peasy ? "

Is this just a byproduct for me using .NET Standard as the only build output and should I add the .NET Framework library back?

Packages such as the following will be added to the project that is wasting my library: even if they are completely unnecessary:

  • System.Security.Cryptography. *
  • System.xml. *
  • System.io. *

etc .. many packages added. My library parses an array of "illustrious" ones and does not require much.

The Visual Studio project is configured to use .NET Standard 1.0, and the only link is "NETStandardLibrary", so I didn’t like the fact that I added all of them.

I inspected the package and it does not seem to list all of these files.

Is it possible to add only those packages that I need and still use .NET Standard 1.0?

My class library is open source: https://github.com/lassevk/DiffLib
The nuget package is here: http://www.nuget.org/packages/difflib/2017.4.24.2347

+5
source share
1 answer

This is a rather difficult situation at the moment:

Is it possible to add only those packages that I need and still use .NET Standard 1.0?

Yes, you can do it, but it is no longer recommended. Essentially, the .NET Standard is a specification consisting of packages that reference it. The supported method is the NETStandard.Library link, because it guarantees you all the necessary links and compilation logic necessary for the correct assembly.

Starting with the upcoming netstandard2.0 , NETStandard.Library will be a flat package without dependencies, and individual packages will be removed from the dependency tree if your project or any other project refers to them. In addition, NETStandard.Library will not be published as a dependency, so if you create the netstandard2.0 library, as a result, the NuGet package will not have any dependencies. ( NETStandard.Library.NETFramework needs to be installed when using it in projects .net framework. NuGet should do this automatically).

If you really want to do this, you can install

 <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences> 

in the csproj , and then add elements such as <PackageReference Include="System.[Something]" Version="4.3.0" /> for everything you need.

+5
source

All Articles