Updating / Restoring Nuget Packages FAST

The VS NuGet client is great for browsing for new packages; in fact it works pretty well for upgrading when your on a small project. But it locks the UI, lags out, if it errors it does so in a useless fashion, the moment you get past a few projects it becomes unbarably slow (especially updating cross solution) and half of the time you just want to stamp on it.

Restoring Nuget Packages

Create a file, call it say Restore.bat, open it in notepad or whatever text editor you like.

My file sits below the source so say c:\project\myproj

@cd src
@echo Starting Restore
@.\.nuget\nuget.exe restore .\myproj.sln -source "https://www.nuget.org/api/v2/"  -NonInteractive -RequireConsent -verbosity detailed
@echo All done
@cd ..

Quick DOS explanation; the @ symbol suppresses printing out the command being called.
So from the myproj folder I cd into src, print out Starting Restore then call nuget from the .nuget folder (you need to obviously have this around) and sets the source to the standard nuget source. In our case we have our own. You might want to tail on to that a myget repo or multiple.

Upgrading your Nuget Repos

As with restore my solution is sat at c:\project\myproj
You have to have all the existing versions of packages downloaded before you can upgrade as nuget uses the packages to determine the dependencies (probably part of why its slow). So it may be prudent to add the restore step prior to the update.

@cd src
@echo Starting Update
@.\.nuget\nuget.exe update .\myproj.sln -source "https://mynugetrepo.com/nuget/"  -NonInteractive -verbosity detailed
@echo All done
@cd ..

The source in the above example is set to a custom nuget store so we just upgrade the ones from our store.

You may want to change that for the main store https://www.nuget.org/api/v2/ but with this you may want to restrict the id's of the projects you upgrade or set the -safe flag to avoid major updates.
Instead of setting the source manually you can set the -ConfigFile PATH flag and use the configuration in your nuget configuration file.

So above you'd swap -source xxx to -configfile ..nuget\nuget.config , by default with no source it would use the nuget.config within your APPDATA folder.

Chris McKee

Chris McKee


Software Engineer, Web Front/Backend/Architecture; all-round tech obsessed geek. I hate unnecessary optimism

View Comments