Matt Davis
Matt Davis

Reputation: 46034

Building w/ NET 6 and Nuget

We have a Windows-only WPF desktop application that we have just migrated from .NET Framework 4.8 to .NET 6.0. We've got everything compiling, but the build system is causing us headaches.

The majority of our code is stored in a git repo that is connected to the internet. When we build, all of the Nuget packages are restored as expected. However, the packages folder now contains well over 200 packages, whereas with .NET Framework 4.8, it only contained those packages we explicitly added via the Nuget Package Manager in Visual Studio (approximately 20).

Q1: My understanding is that this is the way things work now because everything, including any Microsoft, System, and runtime dlls are now Nuget packages themselves. Is my understanding correct?

Now, this would not be a problem except that we have another development environment with its own OFFLINE git repo that includes all of the code from the online git repo PLUS additional code that cannot be included in the online repo. To accomplish this, we periodically have to copy the "online code" to the offline machine, merge the two code bases, and then commit the changes to the offline repo. I hope that's clear.

Since the OFFLINE git repo cannot connect to the internet, we are forced to copy the Nuget packages as well. Again, this was not a problem under .NET Framework 4.8 because it was a small group of packages. Now that the Nuget packages has grown to over 200, the size is nearly 1.5GB, which slows everything down - zipping, copying, burning, unzipping, merging, etc.

What we want to do is have the packages folder just contain those Nuget packages that are REQUIRED to be downloaded from the internet and then pull the other dlls - Microsoft, System, runtime, etc. - from the local system.

Q2: I assume that these packages are all available on the local system when the .NET 6.0 SDK is installed. Is that assumption correct?

We have tried messing around in our nuget.config file and with various MSBuild settings, but to no avail.

Can anyone point us in the right direction?

Upvotes: 0

Views: 505

Answers (1)

svenhuebner
svenhuebner

Reputation: 382

Q1: Yes. Almost everything is a nuget package.

Q2: I don't think so. Only .NET 6 core assemblies are present when the runtime is installed. The "SDK" is (simply speaking) just MSBuild with tasks and .props/.targets files.

TL;DR

Copy only the minimum amount of nupkg files to the offline machine and then establish a local nuget feed there.

Establish the actual dependency packages

In your .NET 6 scenario the nuget package cache (packages folder) is used globally for all restores of the local machine user. This means that ALL projects that are restored by that user will add the transitive closure of their packages to the package cache. Also, every package reference version change will add another package for the new version.

First, make sure is that your size estimate really only contains the packages necessary for that one project. In order to do that, clear the nuget package cache and then fully build the project in question. You can clear the nuget package cache by either simply deleting the entire %userprofile%\.nuget\packages folder or executing nuget locals packages-cache -clear. See also https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders if your folders are non-default. Then look at the packages folder again to see if it really is that big.

Copy only the nupkg files

The next thing is that the packages folder contains both the original nupkg file and then its unzipped contents. It is in a sense much bigger than necessary (on my machine five times as big as just the nupkg files). You can just copy all the nupkg files to your offline machine, say to folder C:\nugettemp. This will greatly reduce the amount of data that needs to be transferred.

Set up a local nuget feed

Then, follow the steps in https://learn.microsoft.com/en-us/nuget/hosting-packages/local-feeds to set up a local nuget feed on the offline machine: execute nuget init C:\nugettemp C:\nugetfeed. Then edit your nuget.config on that machine to only use C:\nugetfeed as package source. You will then be able to do a regular nuget restore without accessing the internet on your offline machine.

Upvotes: 1

Related Questions