【问题标题】:Build Pipeline for dot net core service fails with error 401 (Unauthorized) when provided globalPackagesFolder in nuget.config在 nuget.config 中提供 globalPackagesFolder 时,为 dot net core 服务构建管道失败并出现错误 401(未经授权)
【发布时间】:2020-02-08 16:49:28
【问题描述】:

在 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)'

【问题讨论】:

    标签: azure azure-devops nuget asp.net-core-webapi nuget-package-restore


    【解决方案1】:

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

    根据报错信息:

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

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

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

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

    查看this 线程了解更多详情。

    希望这会有所帮助。

    【讨论】:

    • 感谢@Leo 的回复。我已经在管道中提供了 externalFeedCredentials。仅当我将 添加到 nuget.config 时,管道构建才会失败。在本地解决方案构建上,成功。
    • @manojmore,抱歉稍后回复。直到现在我被邀请到其他线程。您是否尝试过使用 dotnet build --no-restore 添加参数。由于您使用了 nuget restore 解决方案,因此 dotent 构建任务将隐式恢复 nuget 包,但不会使用您的 externalFeedCredentials 。检查docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多