Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio/ NuGet missing references

Tags:

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?

like image 845
Jeremy Holovacs Avatar asked Jun 27 '13 04:06

Jeremy Holovacs


People also ask

How do I fix missing references in Visual Studio?

To fix a broken project reference by correcting the reference path. In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then click the Reference Paths button.

How do I restore references in Visual Studio?

Restore packages (In Visual Studio, the references appear in Solution Explorer under the Dependencies \ NuGet or the References node.) If the package references in your project file are correct, use your preferred tool to restore packages. If the package references in your project file (. csproj) or your packages.

Where are NuGet packages references stored?

Today, a project's NuGet package information is stored in a project-level packages. config folder. The assemblies are stored in a separate packages folder, usually at the solution level.


2 Answers

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.

like image 102
Piotr Stapp Avatar answered Sep 21 '22 13:09

Piotr Stapp


(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!

like image 22
user8451724 Avatar answered Sep 23 '22 13:09

user8451724