Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Download only selected .NET version of a Nuget Package

recently I noticed something, that I never really paid any attention to. I Develop Software in C# and I use Nuget Packages a lot. Even though Nuget console states, that the Nuget Package is downloaded for a specific .NET version, it is always loading multiple Versions wich I wont’t ever need too.

for example I have a WPF Projekt, wich uses the .Net Framework 4.7.2. I add a Nuget Package to that Project, and in addition to the folder net472 there are also folders for net462 net562 netstandard2.0 netstandard2.1 wich I don’t need at all.

what I mean here is the folder structure in the packages folder of my project.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

At the Company I work, we have about 200 Projects in our workspace with 1-5 Nugets per project on average, and I assume, all these additional files over so many projects, will take up a lot of space (my disk drive is slowly approaching its limit), so I’m wondering if there is an option or something, that wil stop nuget from loading files it won’t ever need. I’m using visual studio 2019.

I’ve searched the internet already but found noting so far, as everything that comes up, is how install a specific version of a nuget package, but not how to install it only fo a specific .NET version and nothing else. Also no obvious setting in the visual studio options seems to do what I need.

help would be appreciated

>Solution :

Yes, that’s an unfortunate design decision. A NuGet package is a zip file. If a NuGet package targets different frameworks, its zip file contains the assemblies for all frameworks.

For a .NET Framework solution, NuGet by default creates a packages directory next to the solution file, which contains for each package the .nupkg file as well as its extracted contents.

It also saves a package cache in your user profile. And then there’s the temp directory which contains packages that are being extracted. So all in all, it’s not strange to have a package on disk at least three times, and then once for every .NET Framework project referencing it. And then once in every bin folder.

For some packages that are 1, 10 or even 100 MB, this adds up ridiculously fast, especially on smaller SSDs.

If you have many .NET Framework solutions, a solution (heh) could be to configure a global packages folder, which then contains all extracted packages for your machine as opposed to once per solution directory.

This will however mess up your <Reference><HintPath>...</HintPath></Reference> in your .csproj files, so every developer on your team will then have to configure the exact same packages and source directories.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading