简体   繁体   English

Azure DevOps dotnet build 无权访问 nuget 包

[英]Azure DevOps dotnet build doesn't have access to nuget packages

In Azure DevOps I have my company nuget repository.在 Azure DevOps 我有我的公司nuget存储库。 I have created some new nuget packages and I included them in my projects.我创建了一些新的 nuget 包,并将它们包含在我的项目中。 Locally the projects are working fine.在当地,这些项目运行良好。

When I run the dotnet build on DevOps there is error because there is an unauthorize access to the nuget repository.当我在 DevOps 上运行dotnet build时出现错误,因为存在对 nuget 存储库的未经授权的访问。

在此处输入图像描述

[error]C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): Error: Unable to load the service index for source https://vs.pkgs.visualstudio.com/Vs/_packaging/vs.com/nuget/v3/index.json . [错误]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

Response status code does not indicate success: 401 (Unauthorized).响应状态码不表示成功:401(未授权)。

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

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): error: Response status code does not indicate success: 401 (Unauthorized). C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5):错误:响应状态码不表示成功:401(未授权)。 [d:\a\1\s\PiP.Payments.Stripe\PiP.Payments.csproj] [d:\a\1\s\PiP.Payments.Stripe\PiP.Payments.csproj]

Build FAILED.构建失败。

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

C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): error: Response status code does not indicate success: 401 (Unauthorized). C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5):错误:响应状态码不表示成功:401(未授权)。

We have had this error several times before.我们之前曾多次遇到此错误。 We were always able to fix it with an extra dotnet restore command before the dotnet build command.我们总是能够在dotnet build命令之前使用额外的dotnet restore命令来修复它。

There is a small hint in the documentation here: https://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/dotnet-exe?view=azure-devops#on-build-machines-and-in-non-interactive-scenarios此处的文档中有一个小提示: https://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/dotnet-exe?view=azure-devops#on-build-machines-and-非交互式场景

In Azure Pipelines, use the .NET Core step's restore command, which automatically handles authentication to Azure Artifacts feeds.在 Azure 管道中,使用 .NET 核心步骤的恢复命令,该命令会自动处理对 Azure 工件源的身份验证。 Otherwise, use the Azure Artifacts Credential Provider and pass in credentials using the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable.否则,请使用 Azure 工件凭据提供程序并使用 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS 环境变量传入凭据。

Here is an example yaml:这是一个示例 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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM