c# - Azure Devops 上的 Nuget 还原失败,消息为 "unable to load the service index for source"

标签 c# .net-core nuget azure-devops build-agent

我有一个在私有(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).

构建任务如下:

Nuget restore build task

这是构建代理中 %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 任务时,包恢复没有错误,如下所示:

Build definition

更新 2:

我能够使用 .NET Core 任务 v1 恢复包:

Screenshot - restore packages using the .NET Core task v1

或者使用带有参数 --force 的 v2 任务:

Screenshot - restore packages using --force

最佳答案

对于那些在 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/

相关文章:

.net-core - Identity Server 4登录后重定向仅在Chrome中不起作用

c# - 如何从 mysql 数据库中删除多余的记录并且只有 1 行,

c# - 在代码中创建时的 UITableView 工件

c# - Visual Studio Code Dotnet Core C# : "The type or namespace name ' System' could not be found", 错误但构建成功

c# - 在 ConfigureServices() 中调用 BuildServiceProvider() 的成本和可能的副作用是什么

nuget - 如何使用 Visual Studio for Mac 将图标 URL 添加到我的 Nuget 包

visual-studio - 使用 VS2015 添加需要凭据的 NuGet 包源

nuget - 如何在命令行上将 NuGet 包安装到 Visual Studio 项目

c# - LINQ,查询的大过滤器

c# - 在 C# 和 C++ 中将 float / double 乘以 0.5 而不是除以 2 是否安全?