Search code examples
c#.netnugetautofaclamar

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?


Solution

  • There is no way to predict what will show up in the package, though you have to consider that not only are the dependencies you reference coming in, but also any dependencies those need - the transitive dependencies. Anything that isn't included in the .NET Core App package (think "basic runtime requirements") will have to be packaged.

    You can look on the NuGet page for Lamar and see 2.0.4 needs LamarCompiler and Microsoft.Extensions.DependencyInjection.Abstractions. Those, in turn, need other things.

    I would recommend grabbing NuGet Package Explorer. Once you build your tool package, you can pop it open in this to browse what's actually in there. (Technically, you could also just rename it from .nupkg to .zip and open it, but the explorer makes it nice.)

    After adding Lamar, I see...

    • Lamar.dll
    • LamarCompiler.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

    Most of this appears to be around Roslyn analyzers - the CodeAnalysis stuff. I see that is referenced in the LamarCompiler source though usually I see it set as PrivateAssets=all to ensure it doesn't get bundled into the project and included like this. Normally you don't have Roslyn analyzers as project dependencies since they're build time things. However, I don't know if this is intentional; it may be something you'd want to ask the Lamar folks about. It may be just a small oversight, or there may be a reason.

    TLDR:

    • You can't guess at the size, just build it and look.
    • Use NuGet Package Explorer to see what ended up in the package.
    • Use NuGet pages for packages to see what is chained in.
    • Don't be afraid to go into the source for one of your dependencies to see if it's bringing in something unexpected, and if you see that, ask the respective owner if it's intentional.