简体   繁体   English

NuGet包还原时Team Foundation Service构建失败

[英]Team Foundation Service build fails on NuGet package restore

I'm having kind of an odd problem with my Team Foundation Service build. 我的Team Foundation Service构建遇到了一个奇怪的问题。 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. 然后我按照消息/ URL对构建重新排队,然后......再次发生。 I've Googled around but I can't seem to figure out what the issue is. 我用Google搜索过,但我似乎无法弄清问题是什么。 I can build just fine in Visual Studio and the solution is configured for package restore. 我可以在Visual Studio中构建得很好,并且该解决方案已配置为包还原。 Any thoughts? 有什么想法吗?

Thanks in advance. 提前致谢。

If someone still having this issue on tfs build server you need to go the following: 如果有人在tfs构建服务器上仍有此问题,则需要执行以下操作:

  1. Make sure all projects in solution you attempt to build have the latest Microsoft.Bcl.Build package (just update it in package manager). 确保您尝试构建的解决方案中的所有项目都具有最新的Microsoft.Bcl.Build包(只需在包管理器中更新它)。
  2. After build failed see all project (in tfs build log summary) that generate this error ("The build restored NuGet packages ...") 构建失败后,查看生成此错误的所有项目(在tfs构建日志摘要中)(“构建还原的NuGet包...”)
  3. Open each of those project's .proj file and comment out whole target element started with 'Target Name="EnsureBclBuildImported"' 打开每个项目的.proj文件并注释掉以'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). 在升级之后,不是所有的项目似乎都会删除那些旧的构建代码块并且它会导致问题(据我所知,在Microsoft更改了他们的bcl构建过程之后不再需要它)。

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. 我们更新了Microsoft.Bcl.Build以使用不同的方法。 The new version will use a conditional import similar to what NuGet's automatic import feature does. 新版本将使用类似于NuGet的自动导入功能的条件导入。 This will always allow the project to load in Visual Studio. 这将始终允许项目在Visual Studio中加载。

However, Microsoft.Bcl.Build also adds a target to your project that will run after the build is finished. 但是,Microsoft.Bcl.Build还会为您的项目添加一个目标,该目标将在构建完成后运行。 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): 然后它为构建服务器/持续集成(CI)的情况指定如下:

This solution doesn't address build server / continuous integration (CI) scenarios. 此解决方案不涉及构建服务器/持续集成(CI)方案。 In order to successfully use package restore on the build server, you have two options: 为了在构建服务器上成功使用包还原,您有两个选择:

  1. Check-in the .targets file. 签入.targets文件。
  2. Explicitly run NuGet package restore prior to building your project/solution. 在构建项目/解决方案之前,显式运行NuGet包还原。

So, I suppose for your issue resolution the above two steps should be followed. 所以,我想你的问题解决方案应该遵循以上两个步骤。

I have seen the similar problem in a Xamarin project and doing the following steps fixed my problem; 我在Xamarin项目中看到了类似的问题,并执行以下步骤解决了我的问题;

  1. Set project mode to Release and Rebuild All 将项目模式设置为Release and Rebuild All
  2. Set project mode back to Debug and Rebuild All 将项目模式设置回Debug和Rebuild All
  3. Problem sorted. 问题排序。

Weird but worked for me, hope it helps. 很奇怪,但为我工作,希望它有所帮助。

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. 必须在源代码管理中包含所需的TFSBuild目标文件,或者在尝试构建解决方案之前必须还原NuGet包。

Details on how to do this are provided on the nuget.org . nuget.org上提供了有关如何执行此操作的详细信息。

It basically involves creating a new build project file which first restores packages and then builds your solution. 它主要涉及创建一个新的构建项目文件,该文件首先恢复包然后构建您的解决方案。

Just had the same issue with TeamCity rather than TFS. 刚与TeamCity有相同的问题,而不是TFS。

We're explicitly restoring packages before building, yet some projects still error out on the CI server. 我们在构建之前明确地恢复了包,但是一些项目仍然在CI服务器上出错。

We were able to solve it without hacking the csproj files. 我们能够在不破解csproj文件的情况下解决它。

We forced the build property BclBuildImported = True after restoring packages. 恢复包后,我们强制构建属性BclBuildImported = True The rogue targets in the csproj files are conditional on this property not being set. csproj文件中的流氓目标是以未设置此属性为条件的。

May be a more robust way around it if you can set this property easily in TFS. 如果您可以在TFS中轻松设置此属性,则可能是一种更强大的方法。

I ran into this issue on a Web API project, but we use NAnt. 我在Web API项目中遇到了这个问题,但我们使用NAnt。

The resolution was to update the Microsoft BCL Build Components nuget package to the latest (1.0.21) and things build fine now. 解决方案是将Microsoft BCL Build Components nuget包更新到最新版本(1.0.21)并且现在可以正常构建。

Open the offending csproj in notepad or any other editor. 在记事本或任何其他编辑器中打开有问题的csproj。 Check if the target EnsureBclBuildImported is available in the csproj. 检查目标EnsureBclBuildImported是否在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)' == ''"> <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 ." <错误条件=“!存在('.. \\ packages \\ Microsoft.Bcl.Build.1.0.14 \\ tools \\ Microsoft.Bcl.Build.targets')”Text =“此项目引用缺少的NuGet包在此计算机上。启用NuGet Package Restore以下载它们。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=317567 。“ HelpKeyword="BCLBUILD2001" /> 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 ." <错误条件=“存在('.. \\ packages \\ Microsoft.Bcl.Build.1.0.14 \\ tools \\ Microsoft.Bcl.Build.targets')”Text =“构建恢复NuGet包。再次构建项目以包括这些包在构建中。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=317568 。“ HelpKeyword="BCLBUILD2002" /> HelpKeyword =“BCLBUILD2002”/>
</Target> </目标>

I had to restore packages prior to the clean target of my build script. 我必须在构建脚本的clean目标之前恢复包。 I mistakenly thought restoring packages prior to building was enough. 我错误地认为在建造之前恢复包装就足够了。

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets='GatherBinaries' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>

    <Target Name='RestorePackages'>
        <Exec Command='tools\NuGet.exe Restore "Web.sln"'/>
    </Target>

    <!--
        must call RestorePackages prior to clean to avoid error the following error
        "The build restored NuGet packages. Build the project again to include these packages in the build."
        -->
    <Target Name='Clean' DependsOnTargets='RestorePackages'>
        <MSBuild Projects='Web.sln' Targets='Clean' Properties='Configuration=Release'/>
    </Target>

    <Target Name='Build' DependsOnTargets='Clean;RestorePackages'>
        <MSBuild Projects='Web.sln' Targets='Build' Properties='Configuration=Release'/>
    </Target>

</Project>

Problem Story: 问题故事:

In my case, one of my teammate has used the VisualStudio 2017 . 在我的情况下,我的一个队友使用了VisualStudio 2017 There we have downgrade some nuget packages from the project file by writing versions with hands like postsharp etc. It has worked out on there and he pushed the updated code to the gitlab . 我们已经通过像postsharp等手写版本来从项目文件中降级一些nuget包。它已经在那里工作,他将更新的代码推送到gitlab On my side i have pooled the code from gitlab to my local repo and i have opened it with VisualStudio 2019 and i take this error 在我这边我已经将代码从gitlab汇集到我的本地仓库,我用VisualStudio 2019打开它,我接受了这个错误

Solution: 解:

1- I have opened the code with VisualStudio 2017 from my updated local repo and rebuilt it with it. 1-我已从我更新的本地仓库中使用VisualStudio 2017打开代码并使用它重建。

2- I have closed the VisualStudio 2017 and reopened with VisualStudio 2019 . 2-我已关闭VisualStudio 2017并使用VisualStudio 2019重新打开。 Rebuild is sucessfull this time 这次重建是成功的

For all who faced 对于所有面对的人

The right solution can be found here: https://docs.microsoft.com/ru-ru/nuget/consume-packages/package-restore-troubleshooting 可在此处找到正确的解决方案: https//docs.microsoft.com/ru-ru/nuget/consume-packages/package-restore-troubleshooting

Just add to NuGet.Config: 只需添加到NuGet.Config:

<!-- Package restore is enabled -->
<configuration>
    <packageRestore>
        <add key="enabled" value="True" />
        <add key="automatic" value="True" />
    </packageRestore>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM