Azure Devops 上的 Nuget 还原失败并显示消息“无法加载源的服务索引" [英] Nuget restore fails on Azure Devops with message "unable to load the service index for source"

查看:35
本文介绍了Azure Devops 上的 Nuget 还原失败并显示消息“无法加载源的服务索引"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在私有代理中运行的 .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:Agent01w141sxxxxxxx.sln" (恢复目标) (1) ->(恢复目标)->C:Program Filesdotnetsdk2.1.500NuGet.targets(114,5): 错误:无法加载源

这是构建代理中%appdata%NuGet uget.config文件的内容:

我已经检查了一些类似的问题,但到目前为止我还没有找到解决我的问题的方法.

一些注意事项:

  • 个人访问令牌未过期
  • 此特定构建在其他构建代理中成功运行
  • 至少有 1 个带有nuget restore"任务的构建使用此代理成功运行(常规 nuget restore 任务,而不是 .NET Core)
  • 尝试重新启动构建代理,但没有成功
  • 在恢复之前尝试

    更新 2:

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

    还原包

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

    恢复软件包

    解决方案

    我找到了解决方案 - 将以下包源添加到 %appdata%NuGet uget.config:

    <add key="Microsoft Visual Studio Offline Packages" value="C:Program Files (x86)Microsoft SDKsNuGetPackages"/>

    完整的文件如下所示:

    另外,检查 回归 .NET SDK 500: 'dotnet tool install' failed with 401 (Unauthorized) 当 NuGet.config #7524 中有私人提要时.此问题似乎是由 .NET SDK 2.1.500 引起的.

    另一种解决方法是卸载该版本:

    <块引用>

    该问题在 .NET Core SDK 2.1.400 中不存在,例如它消失了.NET Core SDK 2.1.500 卸载后,SDK 重新出现2.1.500 再次安装.

    I have a build for a .NET solution that is running in a private agent. The solution contains both .NET Core 2.1 and .NET Standard 2.0 projects.

    Some of the nuget packages installed are the following:

    • NETStandard.Library v2.0.3
    • Microsoft.AspNetCore.Mvc v2.0.0
    • Microsoft.NETCore.App v2.1.5

    The build fails when trying to restore the nuget packages with the following error:

    "F:Agent01w141sxxxxxxx.sln" (Restore target) (1) -> (Restore target) -> C:Program Filesdotnetsdk2.1.500NuGet.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 Filesdotnetsdk2.1.500NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized).

    Build task is the following:

    This is the content of %appdata%NuGet uget.config file in the build agent:

    <?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>
    

    I already checked a few similar questions but so far I wasn't able to find a solution for my problem.

    Some notes:

    • Personal Access Token is NOT expired
    • This particular build runs successfully in other build agents
    • There is at least 1 build with a "nuget restore" task that was run successfully using this agent (regular nuget restore task, NOT .NET Core)
    • Tried restarting the build agent, without success
    • Tried specifying a specific version of nuget before the restore, without success
    • .NET Core SDK latest version in the build agent is 2.1.500 (multiple versions installed)

    What am I missing? How to fix this issue? Why can't I restore the packages using the dotnet restore command?

    UPDATE:

    Packages are restored without errors when using the old Nuget Restore task as follows:

    UPDATE 2:

    I am able to restore the packages using the .NET Core task v1:

    Or using v2 task with argument --force:

    解决方案

    I found a solution - add the following package source to %appdata%NuGet uget.config:

    <add key="Microsoft Visual Studio Offline Packages" value="C:Program Files (x86)Microsoft SDKsNuGetPackages" />
    

    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 SDKsNuGetPackages" />
        <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>
    

    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.

    这篇关于Azure Devops 上的 Nuget 还原失败并显示消息“无法加载源的服务索引"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆