gpt4 book ai didi

nuget - 在 msbuild 15 项目中恢复 nuget 包

转载 作者:行者123 更新时间:2023-12-03 18:18:09 24 4
gpt4 key购买 nike

我想在由 msbuild 15 个项目组成的解决方案中从私有(private)提要(vsts 内部提要)恢复 nuget 包,然后构建(并打包)这些项目。

我正在使用我需要构建的 VS 2017 托管代理。

我已经尝试使用启用了(已弃用的)包恢复的 msbuild 进行恢复。这导致没有包被恢复。日志的相关部分:

2017-04-03T12:21:23.5543508Z ##[warning]The 'Restore NuGet Packages' option is deprecated. To restore NuGet packages in your build, add a NuGet Installer task to your build definition.

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 auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework\v4.0.30319'.

我已经尝试使用 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 Version: 3.5.0.1938

2017-04-03T12:21:07.8293660Z System.AggregateException: One or more errors occurred.

---> NuGet.CommandLine.CommandLineException: Failed to load msbuild Toolset

---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

请注意,我传入了 msbuildversion -15 作为附加参数,但 nuget 似乎试图加载 msbuild 14。

我已经尝试使用 dontnet cli dotnet restore 进行恢复。这失败了

2017-04-03T12:21:08.3424716Z [command]C:\Program Files\dotnet\dotnet.exe restore C:\a\1\s\path\to\my\csproj

2017-04-03T12:21:12.8146350Z Restoring packages for 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): error : Unable to load the service index for source 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): error : Response status code does not indicate success: 401 (Unauthorized). [C:\a\1\s\path\to\my\csproj]

2017-04-03T12:21:12.8176375Z ##[error]Dotnet command failed with non-zero exit code: 1.

我的解决方案目录下的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 项目的包,以及如何配置身份验证?

最佳答案

恢复 csproj 项目定义中定义为 PackageReference 元素的 nuget 包需要 nuget 4.0,它不包含在托管生成代理中。

您可以通过在源代码管理树中包含 nuget 4.0 二进制文件并在包还原任务中将该二进制文件作为自定义 NuGet 版本引用来解决此限制。

例如,当您将 nuget 4.0 二进制文件包含在源代码树根目录中名为 nuget4.0.exe 的文件中时,您可以将路径指定为 $(Build .SourcesDirectory)/nuget4.0.exe.

enter image description here

还有一个相关问题here供您引用。

关于nuget - 在 msbuild 15 项目中恢复 nuget 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43184915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com