3

This is a follow-up to a question I had yesterday: NuGet package restore in builds and Visual Studio

I have since removed the ".nuget" solution folder from my VS2013 solution, but the "Visual Studio build" task in my build pipeline now fails, with an error for each project:

[error]xxxxx.csproj(214,5): Error : 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 c:\Temp\VSTS Agent_work\10\s\xxxxx\.nuget\NuGet.targets.

I've tried checking the "Restore NuGet packages" option in the VS build task, but it makes no difference. The checkbox says this option is deprecated, and to use the "Nuget tool installer" task - I've tried this too but it still didn't help.

I've even added a "Nuget (command=restore)" task in my build pipeline. Its output shows that it has restored the Nuget packages into the solution's \packages folder, but again no joy.

I've checked the relative package paths in the .csproj files and they correctly point to the packages folders restored by the above "Nuget restore" task.

Am I missing something or is the only fix to put the ".nuget" solution folder back?

Andrew Stephens
  • 9,413
  • 6
  • 76
  • 152

1 Answers1

7

Found the answer: I needed to remove remnants of the "old way" of package restore from each of my .csproj files, namely:

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<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('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>

As per this SO answer: https://stackoverflow.com/a/23852183/981831

Andrew Stephens
  • 9,413
  • 6
  • 76
  • 152