Maxim T
Maxim T

Reputation: 1282

How to prevent nuget from redundantly restoring packages after opening solution in Visual Studio 2017

Every time i'm opening a solution in Visual Studio 2017 which uses Net.Core SDK it restores packages. It happens all the time, even if i close the solution and open it again.

Why does not it keep a local track of what nuget packages are present on the machine?

Can i make it to behave more logically and first to check it locally for the package presence and to restore it only if it can not be found?

Upvotes: 2

Views: 964

Answers (1)

Leo Liu
Leo Liu

Reputation: 76760

Question: How to prevent nuget from redundantly restoring packages after opening solution in Visual Studio 2017

There is currently no way to disable auto-restore explicitly. Check following thread for more details:

How do I disable restoring NuGet packages while starting the solution

The restore you are seeing there is Auto-Restore which will only run on SDK based projects. https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#automatic-restore-in-visual-studio

There is currently no way to disable auto-restore explicitly but you can disable restore itself. Note that this will disable all restore (on build/rebuild & solution right click restore)

Besides, you do not need to disable it, check the another reason below:

Question: Can i make it to behave more logically and first to check it locally for the package presence and to restore it only if it can not be found?

What nuget is doing now is exactly what you want it to do. Check:

Forcing restore from package sources:

By default, NuGet restore operations use packages from the global-packages and http-cache folders.

So, the restore you are seeing when you open the solution is just check if the packages exists in the global-packages, if not, then nuget start to restore the packages. If packages are exists, nuget does not execute the restore operation. And checking time is very short, about tens of ms. You don't have to worry too much about it.

Hope this helps.

Upvotes: 2

Related Questions