Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix missing nuget references after moving project in Visual Studio 2015

I had a project structure like this:

 WebApp -- WebApp -- WebApp.sln  WebApp.Tests -- WebApp.Tests.csproj 

I moved WebApp.Tests into WebApp using a move (simple click & drag into the WebApp folder). I edited WebApp.sln to fix the project reference so that it will load.

When I build, Nuget complains that packages are missing and to do a restore. I downloaded and used nuget.exe restore on my solution and it reported everything was there.

Based on other Stack Overflow answers, I have tried the following:

  • Edit the test project reference hint paths. I changed from ..\WebApp\packages\PACKAGE to ..\packages\PACKAGE
  • Reload Visual Studio (multiple times)
  • Delete contents of packages folder and bin/obj folders of the projects
  • Use the package manager console to reinstall packages on the Test Project

All of these failed to fix the problem. When I used the package manager to try to reinstall the packages with the command, it gave me the same error that project building does - I must restore the packages first.

Is there any quick way to fix my project? I really don't want to go through each package and uninstall/reinstall manually. Also, how could I have prevented this problem in the first place? Is there a built-in way to move project locations?

like image 295
Nate Hitze Avatar asked Aug 17 '15 17:08

Nate Hitze


People also ask

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.

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.


1 Answers

There was XML similar to this at the end of my project file:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">   <PropertyGroup>     <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>   </PropertyGroup>   <Error Condition="!Exists('..\WebApp\packages\SPECIFICPACKAGE')" Text="$([System.String]::Format('$(ErrorText)', '..\WebApp\packages\SPECIFICPACKAGE'))" /> </Target> 

By changing the ..\Webapp\packages to ..\packages like the rest of the file, my solution compiles just fine now.

like image 100
Nate Hitze Avatar answered Sep 19 '22 22:09

Nate Hitze