简体   繁体   中英

How to restore NuGet packages in Visual Studio without a full NuGet reinstall

I have a project downloaded from a GitHub repository. I try to restore its NuGet packages, but I can't without the full reinstall.

There is a UI option that I'd like to use:

在此处输入图像描述

When I use it, it opens the Solution properties inside the Properties tab.

This is its settings:

在此处输入图像描述

When I try to use the Clear the NuGet package cache , I get the following unhandled exception:

在此处输入图像描述

As there are older references, if I use the Update-Package -reinstall command, every package will be updated to its latest version (unless I do it one by one...for each of the 47 packages...)

I deleted the.nuget folder and after rebuild, it remains empty.

So what are my options to use a working restore? Can I fix somehow the built-in command in Visual Studio?

I tried most of the suggested actions without any success and eventually a complete Visual Studio settings reset was the solution.

You can do it by selecting Tools->Import and Export settings and then choosing Reset all settings . There is an option to save the current settings as backup but I didn't keep them due to their assumed corrupted state.

在此处输入图像描述

It appears to be the nuclear option but it worked.

So what are my options to use a working restore? Can I fix somehow the built-in command in Visual Studio?

Check whether the project from the github has a file called packages.config , if so, which approves that the project uses packages.config to manage nuget packages.

If the project used packages.config nuget management format to manage the package and just delete .nuget folder,then rebuild your project, it did not restore the packages under .nuget folder It actually references the packages from the packages folder under the solution folder.

在此处输入图像描述

So you should also delete the packages folder from the solution folder and then rebuild your project. Then, the packages will be restored under .nuget folder.(it is the specific feature of packages.config ).

=====================================================

If it does not work and to handle the error shown in the screenshot, please try the following suggestions:

Suggestion

1) open Package Source under Tools --> Options --> NuGet Package Manager --> Package Source and then uncheck other feeds except nuget.org . Please retain the

在此处输入图像描述

Also, check whether you have a nuget.config file under the solution folder or above folder, and if so, please check if it has a key called globalPackagesFolder .

Like

<add key="globalPackagesFolder" value="xxxx" />

Please delete it directly and then restart your project.

More info you can refer to this link .

2) close VS, delete global nuget.config file under C:\Users\xxx(current user name)\AppData\Roaming\NuGet .

Also , delete .vs hidden folder under the solution folder, bin and obj folder and restart VS to regenerate the nuget.config file.

3) disable any third party extensions under Extensions --> Manage Extensions

4) If there is any update for VS, please update it.

I had this same problem today, to solve it I went to Tools->Nuget Package Manager->Manage Nuget Packages for Solution. Select any package and uninstall then reinstall that same package. After it's finished installing, all references in the Solution should be updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM