删除Nuget软件包中的间接依赖关系
我正在构建一个Nuget库(.NET标准),并且正在使用其他一些Nuget依赖项。
他们还有其他依赖性,我的代码不需要(我不使用使用该间接依赖的代码)。
有什么方法可以从我的包裹中删除未使用的间接依赖性,因此它会较小?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些间接(或 transitive )依赖关系不会成为nuget软件包的一部分。 Nuget足够聪明,可以检测到并恢复
Nuget上的及传递依赖性RETORERORE YORPACKAGE
。您可以使用Dotpeek这样的工具打开
nupkg
文件时可以轻松检查此问题 - 您不会看到内部的瞬态依赖项。或让我们
newtonsoft.json
:请参阅,当目标.NET标准1.3,例如

system.xml.xmldocument
。但是,当查看“ nofollow noreferrer”> in the Package ,它只是JSON.NET组件:
因此您不必担心。
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:
So you don't have to worry about that.