Azure DevOps dotnet build 无权访问 nuget 包

Enr*_*ico 0 c# nuget .net-core azure-devops

在 Azure DevOps 中,我有我的公司nuget存储库。我创建了一些新的 nuget 包,并将它们包含在我的项目中。在本地,项目运行良好。

当我dotnet build在 DevOps 上运行时出现错误,因为对 nuget 存储库进行了未经授权的访问。

在此处输入图片说明

[错误]C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5):错误:无法加载源https://vs.pkgs.visualstudio.com/Vs/的服务索引 _packaging/vs.com/nuget/v3/index.json

响应状态代码不表示成功:401(未授权)。

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): 错误:无法加载源https://vs.pkgs.visualstudio.com/Vs/_packaging/vs的服务索引 .com/nuget/v3/index.json。[d:\a\1\s\Payments\Payments.csproj]

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): 错误:响应状态代码不表示成功:401(未经授权)。[d:\a\1\s\PiP.Payments.Stripe\PiP.Payments.csproj]

构建失败。

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): 错误:无法加载源https://vs.pkgs.visualstudio.com/Vs/_packaging/vs的服务索引 .com/nuget/v3/index.json。[d:\a\1\s\PiP.Payments.Stripe\PiP.Payments.csproj]

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): 错误:响应状态代码不表示成功:401(未经授权)。

Ale*_*Doe 6

我们以前多次遇到过这个错误。我们总是能够在dotnet restore命令之前使用额外的命令来修复它dotnet build

此处的文档中有一个小提示:https : //docs.microsoft.com/en-us/azure/devops/artifacts/nuget/dotnet-exe?view= azure-devops#on-build-machines- and-非交互式场景

在 Azure Pipelines 中,使用 .NET Core 步骤的 restore 命令,该命令会自动处理对 Azure Artifacts 源的身份验证。否则,请使用 Azure Artifacts 凭据提供程序并使用 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS 环境变量传入凭据。

这是一个示例 yaml:

    - task: DotNetCoreCLI@2
      displayName: 'Restore Packages'
      inputs:
        command: restore
        projects: 'MyCsproj.csproj'
        vstsFeed: 'voxspan'

    - task: DotNetCoreCLI@2
      displayName: 'Build'
      inputs:
        command: build
        projects: 'MyCsproj.csproj'
Run Code Online (Sandbox Code Playgroud)