响应状态代码不表示成功:401 in the task "restore" on the azure-pipeline

Response status code does not indicate success: 401 in the task "restore" on the azure-pipeline

我有以下错误:

error : Unable to load the service index for source https://privateLibrary.com/private/_packaging/privateOrganitation/nuget/v3/index.json. [/home/vsts/work/1/s/Local.Proyect.Core/Local.Proyect.Core.csproj]
       /usr/share/dotnet/sdk/3.0.101/NuGet.targets(123,5): 
error :   Response status code does not indicate success: 401 (Unauthorized). [/home/vsts/work/1/s/Local.Proyect.Core/Local.Proyect.Core.csproj]

我的蔚蓝-pipeline.yml:

variables:
  buildConfiguration: 'Release'
  localProyectName: 'Local.Proyect.Core'
  localProyectCoreDirectory: './Local.Proyect.Core'


trigger:
 branches:
   include:
     - master

steps:
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/$(localProyectName).csproj'
    feedsToUse: config
    nugetConfigPath: $(localProyectCoreDirectory)/NuGet.Config
    arguments: --force

- task: DotNetCoreCLI@2
  displayName: 'Build All'
  inputs:
    projects: '**/$(localProyectName).csproj'
    arguments: '--no-restore --configuration $(buildConfiguration)'

- script: dotnet publish --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(localProyectName) ./$(localProyectName)/$(localProyectName).csproj
  displayName: 'dotnet publish of project $(localProyectName)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: $(localProyectName)'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(localProyectName)'
    ArtifactName: '$(localProyectName)'

命令还原中启动错误。正如您在 azure devops 中看到的那样,机器无法恢复 mi 私有数据包。我在我的应用程序中使用 NuGet.Config "Local.Proyect.Core" 与组织的 URL:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSources>
    <add key="privateOrgnitation" value="https://privateLibrary.com/private/_packaging/privateOrganitation/nuget/v3/index.json." />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>

为什么机器在其他组织中找不到我的 Azure Artifacts?为什么我在 visual studio 中没有出现任何错误,这里是...

Response status code does not indicate success: 401 in the task “restore” on the azure-pipeline

根据错误信息:

Response status code does not indicate success: 401 (Unauthorized)

您似乎没有在 nuget.config 中提供包源的凭据,您可以尝试在 nuget.config 中提供凭据,例如:

<packageSourceCredentials>
    <privateOrgnitation>
        <add key="Username" value="user@contoso.com" />
        <add key="ClearTextPassword" value="YourPassword" />
    </privateOrgnitation>
</packageSourceCredentials>

查看文档 packageSourceCredentials 了解更多详细信息。

希望这对您有所帮助。

好的,自从我遇到这个问题以来等待了很长时间之后,我通过我的代码和 NuGet 包工件的内部组织解决了这个问题。问题是,在 devops 中,我的包在不同的组织中,而且它是一个私有存储库。所以,现在当 azure 机器需要一个工件时,nuget 可以拿走它并用来构建我的项目。

如果您的密码已更改,也会出现此问题。

通过 Windows 中的凭据管理器重置缓存凭据:控制面板 → 所有控制面板项 → 凭据管理器。在 Windows 凭据 下方删除任何名称类似于 VSCredentials_<domain>.

的条目

然后再次尝试构建; Visual Studio 应该询问您当前的密码。