Restoring Nuget References?
I have solution & project in Visual Studio 2012.
The project has a file packages.config
in the root of the project.
For the purposes of this question, lets assume I accidentally removed these libraries from the References
section of my project.
When going into NuGet package manager, the interface is still reporting a tick next to these packages, indicating they are installed.
The only way I can see how to fix this situation is to delete all the entries from packages.config
, which will fix the issue of the NuGet interface reporting them as installed, and re-add each one.
Is there a smarter way? I had hoped enabling 'enable nuget to restore missing packages' would solve this, but it doesnt seem to do anything.
Try re-installing the packages.
In the NuGet Package Manager Console enter the following command:
Update-Package -Reinstall -ProjectName Your.Project.Name
If you want to re-install packages and restore references for the whole solution omit the -ProjectName
parameter.
You need to Enable NuGet package restore at the VS solution level for the restore missing package to work.
In case this helps someone, for me, none of the above was sufficient. I still couldn't build, VS still couldn't find the references. The key was simply to close and reopen the solution after restoring the packages.
Here's the scenario (using Visual Studio 2012):
You open a Solution that has missing packages. The references show that VS can't find them. There are many ways to restore the missing packages, including
nuget restore
if you have the command line nuget installed But no matter what the approach, those references will still be shown as missing. And when you build it will fail. Sigh. However if you close the solution and re-open it, now VS checks those nice <HintPath>
s again, finds that the packages are back where they belong, and all is well with the world.
Update
Is Visual Studio still not seeing that you have the package? Still showing a reference that it can't resolve? Make sure that the version of package you restored is exactly the same as the <HintPath>
in your .csproj file. Even a minor bug fix number (eg 1.10.1 to 1.10.2) will cause the reference to fail. You can fix this either by directly editing your csproj xml, or else by removing the reference and making a new one pointing at the newly-restored version in the packages directory.
上一篇: 如何在Visual Studio 2012或Visual Studio 2013中打开旧的MVC项目?
下一篇: 恢复Nuget引用?