25
votes

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.

7
Might seem silly, but did you check the packages.config file for the library project is present? Ans if you open the Package Manager by right-clicking the project in VS, does it show all packages for the project properly?stijn
Yes, the packages.config file is there and the Package Manager has the Library project ticked with the correct packages.Dave New
have you blown away the NuGet package cache for the machine and the local packages folder by the SLN?Nick Nieslanik
It looks we have the same issue with Rebuild Solution. It doesn't pull any packages from NuGet. Though, if right click a project and choose Build, then it pulls the packages from NuGet.Daniil Veriga

7 Answers

12
votes

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.

21
votes

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.

8
votes

I have the same issue, also on the local machine. Although both Package Manager Console and nuget.exe restore MySolution.sln report that everything is installed, there is no packages folder to be found in the solution directory and no references to packages are being resolved.

I checked all project files and they expect packages to be placed in ..\packages folder, the same folder where the solution file itself is located.

The way I made it work is to run:

nuget.exe restore MySolution.sln -PackagesDirectory packages

This forced nuget.exe to download all packages to the specified folder and all references were restored.

Remember that from NuGet 2.7, the targets file is not supported, msbuild suppose to use some integrated way of restoring packages but it fails very often.

In fact, for my own work I prefer using Paket, which always work, when you get used to it. It also supports target files and nice way to create NuGet packages.

6
votes

I'm not sure about the science behind this, but it worked for me just now after trying to build a freshly-downloaded Visual Studio project, and getting several MSB3245 warnings followed by a build failure due to missing references:

  1. In Visual Studio, right-click on the project with the missing NuGet references, and select "Manage NuGet Packages..."
  2. The Manage NuGet Packages dialog will open. I also saw a message quickly display and then auto-close, with text along the lines of "Restoring NuGet Packages..."
  3. Close the Manage NuGet Packages dialog (without actually changing anything on the dialog), and retry the build.

Edit: Going back in my TimeSnapper auto-screenshot history (no affiliation with that tool -- I'm just a fan), it looks like there was also a message displayed at the top of the Manage NuGet Packages, along with a "Restore" button: "Some NuGet Packages are missing from this solution. Click to restore from your online package sources."

enter image description here

Although the "Restore" apparently automatically happened for me, clicking that button manually might also do the trick to resolve the missing packages issue.

4
votes

Had to uninstall nuget packages and do a refresh install in order to make it work properly. This might help some of you facing the same issue

1
votes

I was having the same problem. In my case, it was a NuGet.Configin the parent directory that was setting <add key="repositorypath" value="C:\CxCache" />. So the nuget restore was copying the packages to a folder I didn't know of. See NuGet Configuration Inheritance.

Deleting the NuGet.Config in the parent directory solved the problem.

0
votes

On Mac; I commited the code to git and deleted everything (main folder), then downloaded it again. Worked afterwards.