NuGet Package Restore is not restoring packages on build

CodeWarrior picture CodeWarrior · Nov 7, 2012 · Viewed 7.9k times · Source

I am moving our source code from Vault to TFS, not bothering with the migration or anything, just pulling a get latest in vault and adding it to TFS.

The solution has got several projects, and each one has at least one NuGet package. I am trying to get Package Restore working again. It worked in Vault (but not the way it was supposed to). I was under a bit of a deadline, and it did not work at first, so I added a Pre-Build event to run nuget.exe against the packages.config for each project.

TFS build service complains about that, so I am trying to get it working "right".

  1. I have set the option in Visual Studio Tools menu.
  2. I have installed NuGetEnablePackageRestore and run the fix.
  3. I have verified that the packages directory is is source control, but is empty.
  4. I have verified that the project files each include the following:
<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

Building with Diagnostic level verbosity reveals that each project evaluates those properties, but the RestoreCommand in nuget.targets is never executed.

Any thoughts?

I have attempted to implement the solutions from these links:

  1. nuget - package restore not working
  2. NuGet Package Restore Not Working - I did post a question/comment on there asking for clarification...
  3. http://nuget.codeplex.com/workitem/1879

Edit

Additionally, I have found that the RestoreCommand property is being evaluated during build. Diagnostic Verbosity shows:

RestoreCommand = (set EnableNuGetPackageRestore=true) && "C:\Source\Kiersted Direct And Related\Direct\Kiersted\.nuget\nuget.exe" install "packages.config" -source "@(PackageSource)" -o "C:\Source\Kiersted Direct And Related\Direct\Kiersted\packages"

Answer

CodeWarrior picture CodeWarrior · Nov 7, 2012

I figured it out, and I found the answer here: MSBuild not running BuildDependsOn tasks from an imported project

The problem (after looking through the Diagnostic verbosity build output) was that the BuildDependsOn setting was getting un-set. My project files each had the import statement

<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

but that statement was at the beginning of the XML tree. Apparently the import for Microsoft.CSharp.targets can interfere with that import and thus the BuildDependsOn.

My solution was to move the nuget.targets import to below the Microsoft.CSharp.targets import. Now everything builds beautifully.