Azure DevOps dotnet build 无权访问 nuget 包 [英] Azure DevOps dotnet build doesn't have access to nuget packages
问题描述
在 Azure DevOps 中,我有我的公司 nuget
存储库.我创建了一些新的 nuget 包,并将它们包含在我的项目中.在本地,项目运行良好.
In Azure DevOps I have my company nuget
repository. I have created some new nuget packages and I included them in my projects. Locally the projects are working fine.
当我在 DevOps 上运行 dotnet build
时出现错误,因为对 nuget 存储库进行了未经授权的访问.
When I run the dotnet build
on DevOps there is error because there is an unauthorize access to the nuget repository.
[错误]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.
[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.
响应状态码不表示成功:401(未授权).
Response status code does not indicate success: 401 (Unauthorized).
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): error : Unable to load the service index for source https://vs.pkgs.visualstudio.com/Vs/_packaging/vs.com/nuget/v3/index.json. [d:\a\1\s\Payments\Payments.csproj]
C:\程序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): error : Response status code does not indicate success: 401 (Unauthorized). [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): error : Unable to load the service index for source https://vs.pkgs.visualstudio.com/Vs/_packaging/vs.com/nuget/v3/index.json. [d:\a\1\s\PiP.Payments.Stripe\PiP.Payments.csproj]
C:\程序Files\dotnet\sdk\3.1.202\NuGet.targets(124,5):错误:响应状态码不表示成功:401(未授权).
C:\Program Files\dotnet\sdk\3.1.202\NuGet.targets(124,5): error : Response status code does not indicate success: 401 (Unauthorized).
推荐答案
我们之前遇到过几次这个错误.我们总是能够在 dotnet build
命令之前使用额外的 dotnet restore
命令修复它.
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.
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
在 Azure Pipelines 中,使用 .NET Core 步骤的 restore 命令,该命令会自动处理对 Azure Artifacts 源的身份验证.否则,请使用 Azure Artifacts 凭据提供程序并使用 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS 环境变量传入凭据.
In Azure Pipelines, use the .NET Core step's restore command, which automatically handles authentication to Azure Artifacts feeds. Otherwise, use the Azure Artifacts Credential Provider and pass in credentials using the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable.
这是一个 yaml 示例:
Here is an example 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'
这篇关于Azure DevOps dotnet build 无权访问 nuget 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!