Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet not restoring packages on build

I have just created a workspace on a new machine, got latest of our project from TFS, enabled NuGet Restore, and I get the following (skimmed-down) output:

1>------ Rebuild All started: Project: Caching, Configuration: Debug Any CPU ------ 1>  Restoring NuGet packages... 1>  To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages'. 1>  All packages listed in packages.config are already installed. 1>  Caching Framework -> C:\MyProjLocation\Caching\bin\Debug\Caching.dll 2>------ Rebuild All started: Project: Library, Configuration: Debug Any CPU ------ 2>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1635,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "LumenWorks.Framework.IO". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. 2>C:\MyProjLocation\Library\SomeClass.cs(2,7,2,17): error CS0246: The type or namespace name 'LumenWorks' could not be found (are you missing a using directive or an assembly reference?)  ========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ========== 

None of the NuGet packages were restored (there are over 10 - I removed them from the above output for readability sake).

It looks like NuGet is not even trying to restore the packages for the second project (Library).

I have already tried moving the NuGet targets import below the CSharp targets import in the Library.csproj file, as mentioned here, but it's still not working:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> 

I am running the latest version of NuGet (2.7.41101.371) on Visual Studio 2013.

Edit: The packages.config exists and the NuGet Package Manager has the Library project ticked with the correct packages.

like image 624
Dave New Avatar asked Dec 24 '13 12:12

Dave New


People also ask

How do I force a NuGet package to restore?

Restore packages manually using Visual StudioEnable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

How do I fix a NuGet package error?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

Was not found it might have been deleted since NuGet restore?

It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. Here are some actions you can take to resolve this error: Add the /restore option to your MSBuild.exe command.


2 Answers

I had to go into Source Control and delete all of the files in the packages folder (except repositories.config) before NuGet would restore the missing packages. The idea is that you are using package restore rather than checking your packages in to source control. If it sees the packages in source control, it won't download them.

like image 102
Chris M. Avatar answered Sep 30 '22 21:09

Chris M.


Have you deleted the NuGet.targets file from disk too?

If the NuGet.targets file is there, Visual Studio / NuGet.exe will try to do the MSBuild package restore.

See this doc for more info.

like image 35
Kevin Kuszyk Avatar answered Sep 30 '22 20:09

Kevin Kuszyk