Rui*_*mba 14 c# build-agent nuget .net-core azure-devops
我有一个在私有代理中运行的.NET解决方案的构建.该解决方案包含.NET Core 2.1和.NET Standard 2.0项目.
安装的一些nuget包如下:
尝试使用以下错误恢复nuget包时,构建失败:
"F:\ Agent01\w\141\s\xxxxxxx.sln"(恢复目标)(1) - >(恢复目标) - > C:\ Program Files\dotnet\sdk\2.1.500\NuGet.targets(114 ,5):错误:无法加载源https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json的服务索引.C:\ Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5):错误:响应状态代码不表示成功:401(未授权).
构建任务如下:
这是%appdata%\NuGet\nuget.config
构建代理中的文件内容:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="MyFeed" value="https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<MyFeed>
<add key="Username" value="LocalBuildAgent" />
<add key="ClearTextPassword" value="xxxxxxxxxxx" />
</MyFeed>
</packageSourceCredentials>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我已经检查了一些类似的问题,但到目前为止,我无法找到解决问题的方法.
一些说明:
我错过了什么?如何解决这个问题?为什么我不能使用dotnet restore
命令恢复包?
使用旧的 Nuget Restore任务时,包可以正确恢复,如下所示:
我可以使用.NET Core任务v1恢复软件包:
或者使用带参数的v2任务--force
:
Jea*_*eau 56
对于那些在 2021 年因相同错误消息而来到这里的人来说,在 pack 命令之前添加 NuGetAuthenticate@1 任务可能是缺失的部分:
- task: NuGetAuthenticate@1
- task: DotNetCoreCLI@2
inputs:
command: 'pack'
packagesToPack: $(projectPath)
includesymbols: true
includesource: true
versioningScheme: 'off'
verbosityPack: Normal
displayName: 'Dotnet Pack'
Run Code Online (Sandbox Code Playgroud)
更新响应以使用 NuGetAuthenticate@1 而不是 NuGetAuthenticate@0 作为响应,以反映 Paul Hatcher 代码中的修订。
Rui*_*mba 10
I found a solution - add the following package source to %appdata%\NuGet\nuget.config
:
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
Run Code Online (Sandbox Code Playgroud)
Complete file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="MyFeed" value="https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<MyFeed>
<add key="Username" value="LocalBuildAgent" />
<add key="ClearTextPassword" value="xxxxxxxxxxx" />
</MyFeed>
</packageSourceCredentials>
</configuration>
Run Code Online (Sandbox Code Playgroud)
Also, check Regression in .NET SDK 500: 'dotnet tool install' fails with 401 (Unauthorized) when there is a private feed in NuGet.config #7524. This problem seems to be caused by .NET SDK 2.1.500.
Another workaround would be to uninstall that version:
The issue is not present in .NET Core SDK 2.1.400, e.g. it goes away when .NET Core SDK 2.1.500 is uninstalled, and reappears when SDK 2.1.500 is installed again.
小智 7
当我尝试构建使用 Azure DevOps 中托管的 NuGet 包的解决方案时,以下步骤帮助我在 Visual Studio 中解决了同样的问题。
希望这也能解决您的问题!
我遇到了同样的问题,但原因不同 - 没有授予 PAT 适当的访问标志。PAT 需要打包(创建、读取、更新和删除提要和包)范围,我之前只将 PAT 设置为具有构建范围(工件、定义、请求、构建队列和更新的构建属性))将 Artifacts 误认为包含私人包源!
VS 中的用户体验(2015 年和 2017 年)根本没有帮助,两个版本都反复弹出凭据对话框,而不是提供有关可能原因的更多信息(除了 401 错误响应之外,线索是不过,在“未经授权”一词中......)。
总结使用私有 DevOps 包源的步骤 -
使用 - 将包源(带有凭据)添加到 %APPDATA%\NuGet\NuGet.config
nuget.exe sources add -name {your_package_feed_name} -source https://pkgs.dev.azure.com/{your_org}/_packaging/{your_feed}/nuget/v3/index.json -username PATForPackages -password {the_pat_value_you_got_from_azure_devops}
Run Code Online (Sandbox Code Playgroud)注意:nuget 源添加会将 Base-64 将 PAT 编码到 packageSourceCredentials 密码设置中。此外,在您的用户配置文件中,NuGet.config 文件相对安全,只要您保证其安全,缺点是这是主机先决条件,这是 nuget 没有内置 Azure DevOps 身份验证的结果。
就我而言,这是一件愚蠢的事情:Azure Devops PAT(个人访问令牌)已过期。
顺便说一句,我建议仅在 nuget.config 文件中指定源,然后按以下方式添加凭据:
dotnet nuget update source your-source-name -u "tour_user@your.domain" -p "PAT obtained from Azure devops with appropriate packaging permissions"
Run Code Online (Sandbox Code Playgroud)
这会将凭据添加到用户配置文件中的文件中,并进行机器编码,因此非常安全。您不应将 PAT 以明文形式公开。
请记住,如果您更改默认过期时间,PAT 默认会在 1 个月内过期,或者最多 12 个月内过期。
归档时间: |
|
查看次数: |
6137 次 |
最近记录: |