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

22,542

Solution 1

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.

Solution 2

I had the same issue where I physically moved a project folder into the src folder and got the missing packages error. My fix was to open up the .csproj file in notepad and replace every instance of this:

..\packages\

with this:

..\..\packages\

It solved the issue...

Share:
22,542
Nate Hitze
Author by

Nate Hitze

Updated on March 05, 2021

Comments

  • Nate Hitze
    Nate Hitze about 3 years

    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?

  • Pritesh Acharya
    Pritesh Acharya over 8 years
    Do you have idea how to restore reference from nuget restore command. I mistakenly delete all my project reference and i don't wanna add it manually.
  • Lee.Winter
    Lee.Winter over 7 years
    Just as future reference - I move my projects into a project folder which causes this problem. ..\packages needs to be changed to ..\..\packages and then add the project back into the solution
  • The Lazy Coder
    The Lazy Coder over 5 years
    Oh My Goodness, I thought I was going insane. Once again, stack overflow to the rescue. Now I know to look at error conditions in the app for these types of ghosts.
  • Hypenate
    Hypenate over 5 years
    For me, I just deleted the XML you mentioned