我有一个在私有(private)代理中运行的 .NET 解决方案的构建。该解决方案同时包含 .NET Core 2.1 和 .NET Standard 2.0 项目。
安装的一些 nuget 包如下:
- NETStandard.Library v2.0.3
- Microsoft.AspNetCore.Mvc v2.0.0
- Microsoft.NETCore.App v2.1.5
尝试恢复 nuget 包时构建失败,出现以下错误:
"F:\Agent01\w\141\s\xxxxxxx.sln" (Restore target) (1) -> (Restore target) -> C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error : Unable to load the service index for source https://xxxxxxxxxx.pkgs.visualstudio.com/_packaging/xxxxxxxxxx/nuget/v3/index.json. C:\Program Files\dotnet\sdk\2.1.500\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized).
构建任务如下:
这是构建代理中 %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>
我已经检查了几个类似的问题,但到目前为止我无法找到解决我的问题的方法。
一些注意事项:
- 个人访问 token 未过期
- 此特定构建在其他构建代理中成功运行
- 至少有 1 个带有“nuget restore”任务的构建使用此代理成功运行(常规 nuget restore 任务,不是 .NET Core)<
- 尝试重新启动构建代理,但没有成功
- 尝试过 specifying a specific version of nuget恢复之前,没有成功
- 构建代理中的 .NET Core SDK 最新版本为 2.1.500(已安装多个版本)
我错过了什么?如何解决这个问题?为什么我不能使用 dotnet restore
命令恢复包?
更新:
使用 old Nuget Restore 任务时,包恢复没有错误,如下所示:
更新 2:
我能够使用 .NET Core 任务 v1 恢复包:
或者使用带有参数 --force
的 v2 任务:
最佳答案
对于那些在 2021 年因相同的错误消息而来到这里的人,在 pack 命令之前添加 NuGetAuthenticate@0 任务可能是缺失的部分:
- task: NuGetAuthenticate@1
- task: DotNetCoreCLI@2
inputs:
command: 'pack'
packagesToPack: $(projectPath)
includesymbols: true
includesource: true
versioningScheme: 'off'
verbosityPack: Normal
displayName: 'Dotnet Pack'
关于c# - Azure Devops 上的 Nuget 还原失败,消息为 "unable to load the service index for source",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53430896/