首页 > 解决方案 > Why after referencing nuget, my packed tool size increased much more comparing with size info provided in nuget.org?

问题描述

Why is there such huge difference between what I see in nuget.org under package download size and size increase after packing with given nuget?

For example: In nuget.org I see that download size of Lamar package is only 140.56 KB. But size of my package grew from ~450KB to ~8 MB after I added Lamar to my project and packet it as dotnet global tool. Then I tried to add different nuget for IOC Autofac. In nuget.org download size of it is 272.5 KB (bigger). But after referencing it and packing my global tool I found that now my package is much smaller (only 516KB vs ~8MB). Why?

Is there any better way to find / predict how much bigger will your nuget package will become after referencing some new nuget?

标签: c#.netnugetautofaclamar

解决方案


无法预测包中将显示什么,尽管您必须考虑不仅是您引用的依赖项,而且包括那些需要的任何依赖项- 传递依赖项。.NET Core 应用程序包中未包含的任何内容(想想“基本运行时要求”)都必须打包。

您可以查看Lamar 的 NuGet 页面并查看 2.0.4 需求LamarCompilerMicrosoft.Extensions.DependencyInjection.Abstractions. 反过来,这些也需要其他东西。

我建议使用NuGet Package Explorer。构建工具包后,您可以在其中打开它以浏览其中的实际内容。(从技术上讲,您也可以将其从 .nupkg 重命名为 .zip 并打开它,但资源管理器使它变得很好。)

添加拉马尔后,我看到...

  • 拉马尔.dll
  • 拉马尔编译器.dll
  • Microsoft.CodeAnalysis.CSharp.dll
  • Microsoft.CodeAnalysis.CSharp.Scripting.dll
  • Microsoft.CodeAnalysis.CSharp.Workspaces.dll
  • Microsoft.CodeAnalysis.dll
  • Microsoft.CodeAnalysis.Scripting.dll
  • Microsoft.CodeAnalysis.VisualBasic.dll
  • Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll
  • Microsoft.CodeAnalysis.Workspaces.dll
  • Microsoft.Extensions.DependencyInjection.Abstractions.dll
  • System.Composition.AttributedModel.dll
  • System.Composition.Hosting.dll
  • System.Composition.Runtime.dll
  • System.Composition.TypedParts.dll

其中大部分似乎与 Roslyn 分析器有关 - CodeAnalysis 的东西。我看到在 LamarCompiler 源代码中引用了它,尽管通常我看到它设置为PrivateAssets=all确保它不会被捆绑到项目中并像这样包含。通常你没有 Roslyn 分析器作为项目依赖项,因为它们是构建时间的东西。但是,我不知道这是否是故意的;这可能是你想问拉马尔人的事情。这可能只是一个小小的疏忽,也可能是有原因的。

TLDR:

  • 您无法猜测大小,只需构建并查看即可。
  • 使用 NuGet 包资源管理器查看包中的内容。
  • 使用包的 NuGet 页面查看链接的内容。
  • 不要害怕进入其中一个依赖项的源代码,看看它是否带来了意想不到的东西,如果你看到了,请询问各自的所有者是否是故意的。

推荐阅读