我想从私有源(vsts内部源)中还原解决方案中的nuget程序包(由msbuild 15项目组成),并随后构建(和打包)这些项目。
我正在使用需要构建的VS 2017托管代理。
我尝试启用了已弃用的包恢复,使用msbuild进行还原,但是没有还原任何包。以下是日志文件的相关部分:
2017-04-03T12:21:23.5543508Z ##[warning]“还原NuGet程序包”选项已过时。要在您的构建中还原NuGet程序包,请向您的生成定义添加一个NuGet安装程序任务。
2017-04-03T12:21:23.5803410Z ##[command]"C:\LR\MMS\Services\mms\TaskAgentProvisioner\Tools\agents\2.115.0\externals\nuget\NuGet.exe" restore "C:\a\1\s\mysolution.sln" -NonInteractive
2017-04-03T12:21:24.5231560Z MSBuild自动检测: 从'C:\Windows\Microsoft.NET\Framework\v4.0.30319'中使用版本为“4.0”的msbuild。
我尝试使用nuget安装程序任务进行还原。但是失败了:
2017-04-03T12:21:05.3231625Z [command]C:\a_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.29\node_modules\nuget-task-common\NuGet\3.5.0\NuGet.exe restore -NonInteractive C:\a\1\s\mysolution.sln -Verbosity Detailed -msbuildversion 15
2017-04-03T12:21:07.5100892Z NuGet版本: 3.5.0.1938
2017-04-03T12:21:07.8293660Z System.AggregateException: 发生了一个或多个错误。
---> NuGet.CommandLine.CommandLineException: 加载msbuild工具集失败
---> System.IO.FileNotFoundException: 找不到文件“Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或它的某个依赖项。系统无法找到指定的文件。
需要注意的是,我传递了msbuildversion -15
作为附加参数,但似乎nuget尝试加载msbuild 14。
我尝试使用dontnet cli dotnet restore
进行还原,但是失败了:
2017-04-03T12:21:12.8146350Z 正在恢复C:\a\1\s\path\to\my\csproj的包...
2017-04-03T12:21:12.8146350Z C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5)错误:无法加载源 https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json. [C:\a\1\s\path\to\my\csproj]
2017-04-03T12:21:12.8146350Z C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5)错误:返回状态代码表明失败:401(未经授权)。[C:\a\1\s\path\to\my\csproj]
2017-04-03T12:21:12.8176375Z ##[error]Dotnet命令以非零退出代码失败。
我的解决方案目录中的nuget.config
如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="VSTS Tools Feed" value="https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json" />
</packageSources>
<apikeys>
<add key="https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json" value="<A PAT generated from an account with access to the feed>" />
</apikeys>
</configuration>
任务日志显示配置文件已被使用。
在VS中或使用Nuget 4.0的Nuget CLI本地打包还原工作正常。
我应该使用哪个任务来为MSBuild 15项目还原包,并如何配置身份验证?