gpt4 book ai didi

azure - 在 nuget.config 中提供 globalPackagesFolder 时,为 dot net core 服务构建管道失败,并出现错误 401(未经授权)

转载 作者:行者123 更新时间:2023-12-05 06:23:25 25 4
gpt4 key购买 nike

在 ADO 中为 dot net core 服务构建管道时遇到一个奇怪的问题。

我正在尝试为 nuget.config 文件中引用的包设置路径。下面是 nuget.config 文件。

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositorypath" value="..\..\Packages" />
<!--Affects projects using PackageReference only-->
<add key="globalPackagesFolder" value="..\..\Packages" />
<add key="dependencyversion" value="HighestMinor" />
</config>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="NuGet Server" value="my private feed" />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<disabledPackageSources />
</configuration>

添加以下行后,出现 401 Unauthorized。

<add key="globalPackagesFolder" value="..\..\Packages" />

异常

Retrying 'FindPackagesByIdAsync' for source 'myfeed/nuget/v3/flat2/microsoft.extensions.dependencyinjection/index.json'.
Response status code does not indicate success: 401 (Unauthorized).
Restore failed in 8.09 sec for /home/vsts/work/1/s/Service/Test/myproject.Tests/myproject.Tests.csproj.

以下是构建管道中的任务

pool:
vmImage: 'ubuntu-latest'

variables:
buildConfiguration: 'Release'

steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
inputs:
#command: 'restore'
restoreSolution: 'Service/myservice.sln'
feedsToUse: config
nugetConfigPath: 'Service/.nuget/nuget.config'
externalFeedCredentials: 'MyPackages'

- script: dotnet build "Service/myservice.sln" --configuration $(buildConfiguration) -p:langversion=latest
displayName: 'dotnet build $(buildConfiguration)'

最佳答案

Build Pipeline for dot net core service fails with error 401 (Unauthorized) when provided globalPackagesFolder in nuget.config

根据错误信息:

Retrying 'FindPackagesByIdAsync' for source 'myfeed/nuget/v3/xxx'.
Response status code does not indicate success: 401 (Unauthorized).

我们可以知道它正在尝试访问您的私有(private) nuget feed 并收到此 401(未经授权)错误。您似乎没有在 nuget.config 文件中提供认证信息。

要解决此问题,请尝试在 nuget.config 中添加认证信息,如下所示:

  <packageSourceCredentials>
<NuGet Server>
<add key="Username" value="xxxxx" />
<add key="ClearTextPassword" value="Password/PAT" />
</NuGet Server>
</packageSourceCredentials>

检查this线程了解更多详细信息。

希望这有帮助。

关于azure - 在 nuget.config 中提供 globalPackagesFolder 时,为 dot net core 服务构建管道失败,并出现错误 401(未经授权),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58336502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com