Search code examples
nuget.net-standard-2.0

Removing indirect dependencies in NuGet Package


I'm building a NuGet library (.NET standard), and I'm using some other NuGet dependencies.

They have other dependencies that my code doesn't need (I don't use the code that use that indirect dependencies).

Is there any way to remove the unused indirect dependencies from my package, so it will be smaller?


Solution

  • Those indirect (or transitive) dependencies won't become part of your NuGet package. NuGet is smart enough to detect that and restore the transitive dependencies on nuget restore YourPackage.

    You can easily check this when opening your nupkg file with a tool like dotPeek - you won't see the transient dependencies inside.

    Or let's take Newtonsoft.Json: as you can see in the sources, a bunch of other packages are referenced when targeting .NET Standard 1.3, e. g. System.Xml.XmlDocument.
    But when looking inside the package, it's only the Json.NET assembly: enter image description here

    So you don't have to worry about that.