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.
The following script can be run in the Package Manger Console window, and will remove all packages from each project in your solution before reinstalling them.
This will run every package's install script again, which should restore the missing assembly references. Unfortunately, all the other stuff that install scripts can do -- like creating files and modifying configs -- will also happen again. You'll probably want to start with a clean working copy, and use your SCM tool to pick and choose what changes in your project to keep and which to ignore.
Unistall all package and remove depencies
Clear the packages folder in the root of project
Copy the modifies package.config to root folder of website
Run this code to restore the project
I added the DLLs manually. Right clicked on References in the project, select Add Reference and then in the dialog pressed the Browse button. The NuGet DLLs where in the packages directory of the solution. To get the names of them you can right click on references in another project that's working properly and select properties and look in the path property.
This script will reinstall all packages of a project without messing up dependencies or installing dependencies that may have been intentianlyz removed. (More for their part package developers.)
In Visual Studio 2015 (Soulution is under source control, MVC-Project), csano's
Update-Package -Reinstall -ProjectName Your.Project.Name
worked, but it messed up with some write locks.I had to delete the "packages"-Folder manually before. (It seemed to be locked because of the source control).
Also, I had to re-install the MVC-Package from the NuGet Package Manager.
I have to agree with @Juri that the vastly popular answer by jmfenoll is not complete. In the case of broken references, I submit that most of the time you do not want to update to the latest package, but only fix your references to the current versions that you happen to be using. And Juri provided a handy function
Sync-References
to do just that.But we can go just a bit further, allowing the flexibility to filter by project as well as package: