Team Foundation Service build fails on NuGet package restore

22,711

Solution 1

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.

Solution 2

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).

Solution 3

I have seen the similar problem in a Xamarin project and doing the following steps fixed my problem;

  1. Set project mode to Release and Rebuild All
  2. Set project mode back to Debug and Rebuild All
  3. Problem sorted.

Weird but worked for me, hope it helps.

Share:
22,711
benjy
Author by

benjy

Updated on May 24, 2020

Comments

  • benjy
    benjy almost 4 years

    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.

  • benjy
    benjy over 10 years
    Apparently I somehow completely missed that even though I read the document multiple times. Awkward. Thanks.
  • reallyJim
    reallyJim over 10 years
    This definitely solved my issues, after trying to sort out the issue for a few hours.
  • Shaun Wilson
    Shaun Wilson over 10 years
    the BCL targets file has been nothing but a headache since it was introduced. this isn't actually a solution because the next time you update the package the faux errors are re-added. i really hope whoever manages this at Microsoft can get a clue and undo the mess they've created. it has caused more problems than it has solved, and it continues plaguing us over time. this is a clear case of a lack of dogfooding and oversight, it only ever works in the simplest scenario and it's meant to solve an imaginary problem. frustrating garbage !@#$
  • Jamie Hammond
    Jamie Hammond over 10 years
    Is this the actual solution for the question? The question is about TFS builds and not builds in VS. Im looking for the solution for TFS if anyone can help. Thanks
  • Dave New
    Dave New about 10 years
    @ShaunWilson: I cannot agree with you more. It has been a huge pain for us as well.
  • Jostein Kjønigsen
    Jostein Kjønigsen about 10 years
    Seconding (thirding?) this. Making the build-process a dynamic dependency of the build-process itself is bound to fail. Coupled with the limitations of TFS's CI build, this is a recipe for disaster.
  • John H
    John H about 10 years
    @Jamie Hammond The answer explicitly mentions 2 options for the CI server.
  • George Stocker
    George Stocker over 9 years
    It sounds like this covers Nuget pre 2.7/ Post 2.7 the TFS build server is supposed to be able to do this automagically when you use the newest Build Templates.
  • Craig Brett
    Craig Brett about 9 years
    @George, it's supposed to post 2.7, it doesn't though. Judging from our problems. Having to go with checking in the .targets file into CI.
  • George Stocker
    George Stocker about 9 years
    @CraigBrett Make sure you're using the newest build templates from 2013. If you imported your build template from TFS 2012, you won't be able to use the newfangled awesome way of Nuget Package Restore.
  • Jaider
    Jaider almost 9 years
    My problem is how to implement step 2... Should add sort of nuget definition/command inside each .csproj?
  • AlbatrossCafe
    AlbatrossCafe over 8 years
    This just hides the error - but it doesn't actually solve it? How do I know if my project will run if I ignore this error?
  • mai
    mai almost 5 years
    wow... this just worked! Unbelievable. Tried with asp.net core project