TFS Build 2015 由于 NuGet 版本不正确而失败,即使构建机器中存在所需的版本也是如此

TFS Build 2015 failing because of incorrect NuGet version even when the required one is present in the build machine

我正在使用新的可编写脚本的系统配置 TFS 2015 版本。在构建期间,当 NuGet 恢复某些包时,它失败并出现以下错误:

The 'System.Collections 4.0.10' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

The 'System.Diagnostics.Debug 4.0.10' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

The 'System.Globalization 4.0.10' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

The 'System.Linq 4.0.0' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

The 'System.Resources.ResourceManager 4.0.0' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

The 'System.Runtime 4.0.20' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

The 'System.Runtime.Extensions 4.0.10' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

The 'System.Threading 4.0.10' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.

顺便说一句,我已经在整个构建机器中安装了 Visual Studio 2015,并且我检查了扩展管理器菜单中是否存在 NuGet 3.1。

我想 TFS Build 使用了不同的 NuGet 安装位置,但我不知道在哪里寻找它以及如何将它从 2.8.x 更新到 3.x。

比我想象的要容易...

检查 TFS 构建日志后,我发现了以下字符串:

X:\TfsBuild\Agents\project\agent\worker\tools\NuGet.exe restore "X:\TfsBuild\Agents\project\c57207ab\path\to\solution\whatever.sln" -NonInteractive

也就是说,当从 TFS Web Access 下载 TFS 构建代理 ZIP 时,它包含一个过时的 NuGet 可执行文件。

最糟糕的是没有公开可用的 NuGet 命令行 3.x 可执行文件,我需要使用 Google 一次 I've found a post in the official NuGet blog pointing to a NuGet Command-Line 3.1 beta version executable 我已经替换了构建代理中的那个使用 beta 工具定位,错误得到修复。

该问题还会影响 XAML 构建

如果您想使用 XAML 构建,您需要下载相同的 NuGet 命令行可执行文件并将其复制到 C:\Program Files\Microsoft Team Foundation Server 14.0\Tools\nuget.exe 并替换现有的...

这个问题有一个解决方法。

默认情况下,如果您使用VSBuild/MSBuild个任务,您只能通过相应的复选框选择是否运行 nuget restore。但是有一个名为 NuGet Installer 的单独任务(它位于 Package 部分)。它为 NuGet.exe:

的自定义路径公开了一个可选字段

所以,我的想法是:

  • 在适当的 VSBuild/MSBuild 步骤
  • 之前安排 NuGet 安装程序 步骤
  • 指定正确的自定义路径 NuGet.exe
  • 确保 恢复 NuGet 程序包 标志 关闭 VSBuild/MSBuild 步骤

注意:您在构建代理内部直接替换物理可执行文件的解决方案可能会很好地工作,直到代理被更新(有意或以某种方式自动)并用更新的覆盖 NuGet.exe,但仍然过时的版本。

我遇到了同样的问题。您需要使用 更新版本的 nuget.exe。版本 3.5.0 解决了我的问题。

您可以在这里下载 Nuget 发行版:https://dist.nuget.org/index.html

您的解决方案顶部应该有一个 .NuGet 文件夹。 TFS 将使用此文件夹中的 nuget.exe 进行程序包还原操作。

  • 访问此 URL:https://dist.nuget.org/index.html
  • 下载最新的nuget.exe
  • 从 .nuget 文件夹中删除现有 nuget.exe。
  • 使用 add/existing 项将新 nuget.exe 添加到此文件夹。
  • 签入更改。

您现在应该能够对构建进行排队并成功恢复包。