21

I had some problems with my solution's references since somebody went and messed up NuGet... restoring from source control rendered the projects unloadable, and I had to play around a bit to finally get things to load. When I was finally able to get my projects to load properly (after one heck of a headache), I had a pretty big experimental mess to clean up, and now nothing builds.

Nuget thinks my dependencies are installed. Visual Studio disagrees.

enter image description here

What do I have to do to make NuGet and Visual Studio agree with each other?

5 Answers 5

14

It is not simple but try following steps:

  1. In package manager console restore your nuget packages
  2. Open csproj in notepad and check if paths are correct. If not repair them.
  3. If above steps won`t work in package manager console reinstall all your packages.
  4. If the project is open, Unload it, then Reload it. This forces Visual Studio to re-resolve the references.

Explanation:

When nuget add reference it add it in csproj like below:

<Reference Include="Newtonsoft.Json"> <HintPath>..\packages\Newtonsoft.Json.4.5.9\lib\net40\Newtonsoft.Json.dll</HintPath> </Reference> 

Which means that package number is in HintPath. After you merge two branches, the nuget version numbers probably changed. This causes that HintPath should also be changed to proper path with version. That is why Visual Studio has problems to find them.

Sign up to request clarification or add additional context in comments.

3 Comments

Can you elucidate on your answer?
I basically had to rebuild that entire XML file. What a PITA.
In my case, I moved my project one folder down the tree but did not add an extra "..\" to the HintPath of the nuget referenced libraries.
3

(VisualStudio 2017). None of the suggestions here worked... --until I completely closed out of VisualStudio and restarted it. It took a couple seconds longer than usual, but all the dependencies were restored thereafter!

Comments

1

In your Visual Studio Solution folder, open the 'packages' folder and delete everything which is inside that folder. Then restore nuget packages.

1 Comment

This is extremely valid. Just doing a NuGet restore alone does not work and rewrites your packages.config file without all required dependencies.
0

In Visual Studio 2017 for Asp.Net Core project it was enough to unload and then reload .csproj file

Comments

0

I tried all the answers on here. Running Update-Package -reinstall did help a little, but there were still references that just wouldn't get fixed. I noticed that even if I uninstalled them in NuGet, the reference was still in the project.

I ended up having to write down all the missing references in order of dependency, uninstall them with NuGet, remove the references from the project, and reinstall in NuGet. It was a big tedious pain but it got the job done.

Comments