Team Foundation Service build fails on NuGet package restore

后端 未结 10 1894
半阙折子戏
半阙折子戏 2020-12-13 02:23

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:



        
相关标签:
10条回答
  • 2020-12-13 03:01

    Either the required TFSBuild targets files must be included in source control or the NuGet packages must be restored prior to attempting to build the solution.

    Details on how to do this are provided on the nuget.org.

    It basically involves creating a new build project file which first restores packages and then builds your solution.

    0 讨论(0)
  • 2020-12-13 03:03

    Just had the same issue with TeamCity rather than TFS.

    We're explicitly restoring packages before building, yet some projects still error out on the CI server.

    We were able to solve it without hacking the csproj files.

    We forced the build property BclBuildImported = True after restoring packages. The rogue targets in the csproj files are conditional on this property not being set.

    May be a more robust way around it if you can set this property easily in TFS.

    0 讨论(0)
  • 2020-12-13 03:10

    I ran into this issue on a Web API project, but we use NAnt.

    The resolution was to update the Microsoft BCL Build Components nuget package to the latest (1.0.21) and things build fine now.

    0 讨论(0)
  • 2020-12-13 03:10

    Open the offending csproj in notepad or any other editor. Check if the target EnsureBclBuildImported is available in the csproj. If so, comment out the second error condition inside the target that directs the build to fail even if the package is available (its like fail the build regardless of the package is available or not!).

    <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">

    <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="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=317567." HelpKeyword="BCLBUILD2001" />

    <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="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." HelpKeyword="BCLBUILD2002" />
    </Target>

    0 讨论(0)
  • 2020-12-13 03:21

    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.

    0 讨论(0)
  • 2020-12-13 03:21

    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.

    0 讨论(0)
提交回复
热议问题