TFS 2017 构建定义中使用的 NuGet Installer 任务无法清除 global-packages 文件夹并出现错误

The NuGet Installer task used in TFS 2017 build definition fails to clear the global-packages folder with an error

我们有一个在 TFS 2017 中创建的构建定义,它构建了一个依赖于我们的一些 NuGet 包的 .net 解决方案,在编译期间,该解决方案从存在的包 (global-packages) 文件夹中恢复 NuGet 包在此路径 %userprofile%\.nuget\packages 而不是从我们的内部提要下载最新的。

我在这个 page 看到一个命令来避免使用全局包文件夹,但是当我在 NuGet 安装程序任务中添加 nuget locals global-packages -clear 参数时,它用于恢复 nuget 包,任务失败,出现以下错误 unknown option -Clear.

任务中我使用的NuGet版本是3.5.0

2019-09-05T09:27:18.8819742Z ##[section]Starting: NuGet restore $(build.sourcesdirectory)/IntelliSuiteService.sln
2019-09-05T09:27:18.8819742Z ==============================================================================
2019-09-05T09:27:18.8819742Z Task         : NuGet Installer
2019-09-05T09:27:18.8819742Z Description  : Installs or restores missing NuGet packages
2019-09-05T09:27:18.8819742Z Version      : 0.2.31
2019-09-05T09:27:18.8819742Z Author       : Microsoft Corporation
2019-09-05T09:27:18.8819742Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613747)
2019-09-05T09:27:18.8819742Z ==============================================================================
2019-09-05T09:27:19.4601187Z [command]C:\Windows\system32\chcp.com 65001
2019-09-05T09:27:19.4757465Z Active code page: 65001
2019-09-05T09:27:19.5069958Z Detected NuGet version 3.5.0.1938 / 3.5.0
2019-09-05T09:27:19.5226206Z SYSTEMVSSCONNECTION exists true
2019-09-05T09:27:19.5226206Z [command]F:\Builds\NextGen_Gated\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b[=10=].2.31\node_modules\nuget-task-common\NuGet.5.0\NuGet.exe restore -NonInteractive F:\Builds\NextGen_Gated\s\SuiteService.sln -NoCache nuget locals global-packages -Clear
2019-09-05T09:27:20.1007732Z Unknown option: '-Clear'
2019-09-05T09:27:20.1163983Z ##[error]Error: F:\Builds\NextGen_Gated\_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b[=10=].2.31\node_modules\nuget-task-common\NuGet.5.0\NuGet.exe failed with return code: 1
2019-09-05T09:27:20.1163983Z ##[error]Packages failed to install
2019-09-05T09:27:20.1320334Z ##[section]Finishing: NuGet restore $(build.sourcesdirectory)/SuiteService.sln

您应该 运行 该命令与 nuget restore 命令分开。

您可以登录到代理机器并从命令行运行它,或者在构建中添加一个命令行或批处理任务运行命令。