Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Team Foundation Service build fails on NuGet package restore

I'm having kind of an odd problem with my Team Foundation Service build. I queue it up and it starts just fine, but then it fails with the following error:

C:\a\src\Platform\Prod\Platform.Web\Platform.Web.csproj (436): The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568. 

So then I re-queue the build per the message/URL and...it happens again. I've Googled around but I can't seem to figure out what the issue is. I can build just fine in Visual Studio and the solution is configured for package restore. Any thoughts?

Thanks in advance.

like image 705
benjy Avatar asked Sep 24 '13 18:09

benjy


People also ask

How do I fix NuGet recovery failed?

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.

How do I force a NuGet package to restore?

Restore NuGet packagesNavigate to Tools > Options > NuGet Package Manager > General, and then select the Allow NuGet to download missing packages check box under Package Restore. Enabling Restore NuGet Packages. In Solution Explorer, right-click the solution, and then select Restore NuGet Packages.

What is NuGet restore in TFS build?

We use most is Nuget restore in TFS build definition. To promote a cleaner development environment and to reduce repository size, NuGet Package Restore installs all a project's dependencies as listed in either the project file or packages.config .

How do I clean my NuGet package?

Open Visual Studio, go to Tools -> NuGet Package Manager -> Package Manager Settings menu. Click Clear All NuGet Cache(s) button in options dialog then clearing process is started. Once NuGet cache location is cleared, click ok button.


2 Answers

If someone still having this issue on tfs build server you need to go the following:

  1. Make sure all projects in solution you attempt to build have the latest Microsoft.Bcl.Build package (just update it in package manager).
  2. After build failed see all project (in tfs build log summary) that generate this error ("The build restored NuGet packages ...")
  3. Open each of those project's .proj file and comment out whole target element started with 'Target Name="EnsureBclBuildImported"'
  4. Check in and retry the build

It seems somehow after upgrading not all projects get those old block of build code removed and it's causing problems (as I understand it it's not longer needed after microsoft changed their bcl build process).

like image 121
Michael Logutov Avatar answered Sep 23 '22 18:09

Michael Logutov


The solution to this is specified in link in the error message itself.

This is happening due to an Improvement as specified in that page:

The Improvement

We’ve updated Microsoft.Bcl.Build to use a different approach. The new version will use a conditional import similar to what NuGet’s automatic import feature does. This will always allow the project to load in Visual Studio.

However, Microsoft.Bcl.Build also adds a target to your project that will run after the build is finished. This target checks whether the current build restored packages and if so fail the build with an actionable error message:

Building a second time will fix this error. Please note that this error will only appear if packages were missing so it’s not like you always have to build twice.

Then it specifies as below for the case of build server / continuous integration (CI):

This solution doesn’t address build server / continuous integration (CI) scenarios. In order to successfully use package restore on the build server, you have two options:

  1. Check-in the .targets file.
  2. Explicitly run NuGet package restore prior to building your project/solution.

So, I suppose for your issue resolution the above two steps should be followed.

like image 35
RinoTom Avatar answered Sep 20 '22 18:09

RinoTom