27

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.

Community
  • 1
  • 1
Dave New
  • 38,496
  • 59
  • 215
  • 394
  • 2
    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 Dec 24 '13 at 13:34
  • Yes, the packages.config file is there and the Package Manager has the Library project ticked with the correct packages. – Dave New Dec 24 '13 at 14:02
  • have you blown away the NuGet package cache for the machine and the local packages folder by the SLN? – Nick Nieslanik Dec 29 '13 at 06:25
  • 1
    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 Apr 08 '14 at 22:10

7 Answers7

21

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.

Chris M.
  • 608
  • 6
  • 10
12

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.

Brien Foss
  • 3,336
  • 3
  • 21
  • 31
Kevin Kuszyk
  • 1,958
  • 24
  • 37
  • This link is valid for VS13 but, apparently, in VS15, there's no such thing anymore. I have a folder called *packages* and a file called *packages.config*. That's it. When I drop the folder or any of its contents, it's being restored upon build. Pure magic, hehe! But that's on my local machine. When I push the stuff to autobuild on Visual Studio Online, it doesn't restore the packages (although I selected VS2015 as the building agent setting). – Konrad Viltersten Jan 16 '16 at 12:46
  • Visual Studio will still use the `.nuget` folder if you create one (you can put a `nuget.config` in there for example), but it's not created by default any more. And yes, as you've noticed Visual Studio will now try to restore packages before it builds. On your build server you'll need to run `nuget restore` in a build step before you build the solution. – Kevin Kuszyk Jan 18 '16 at 08:50
  • Actually, what I noticed after crying my butt off is that there's no need for the pre-step restoring the packages anymore! If you're using VS2015 in the build step (only step I had in my test), it actually restores the packages for you. This is potentially confusing but oh so nice. And obvious, in some sense! Yey VS15, hehe. – Konrad Viltersten Jan 18 '16 at 18:46
  • Which build server are you using? On AppVeyor and TeamCity I have to restore the packages before building the solution. – Kevin Kuszyk Jan 19 '16 at 08:38
  • I'm using Visual Studio Online (which, despite the name, is anything but Visual Studio). Please note that it's **not the build server** that's the thing here. It's **the agent**. If I choose VS2013 as profile, I need to restore too (the same if I'd compile locally on VS13. However, when I compile from VS15 (or choose the profile VS15 on the build server), it's being handled automagically. So, my **guess** would be that TC will do that too - but only if you select target agent (environment or whatever JetBrains called it) to VS2015. Kind of awesome, in my view. Could you verify it and tell me? – Konrad Viltersten Jan 19 '16 at 09:06
  • I guess Microsoft must have put some of that magic into the VSTS build agent. I just tried both AppVeyor and TeamCity on the Visual Studio 2015 profile and neither of them automatically restored the packages. – Kevin Kuszyk Jan 21 '16 at 12:03
  • I'm not enough savvy on the issue to offer an explanation but I might speculate that TC and AV didn't implement the agent correctly, perhaps? I'm thinking about my local VS15 - it restores too. On the other hand, MS might have put in some of that magic into VS15 specifically (and the online build server). In that case, they kind of locked TC out... Confusing to the developers, in my view... – Konrad Viltersten Jan 21 '16 at 20:26
9

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.

Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83
6

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.

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
4

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

Gabriel Marius Popescu
  • 2,016
  • 2
  • 20
  • 22
1

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.

naicolas
  • 138
  • 6
0

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