启用自包含功能会导致dotnet发布因私有NuGet而失败

时间:2019-07-29 12:22:09

标签: azure-devops azure-pipelines

启用私有的发布会导致在使用私有NuGet feed进行身份验证时发生错误。没有“ --self-contained true”,一切运行正常,出现以下错误。 我该怎么解决?

##[section]Starting: Publish
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.154.6
Author       : Microsoft Corporation
Help         : [Learn more about this task](https://go.microsoft.com/fwlink/?linkid=832194) or [see the .NET Core documentation](https://docs.microsoft.com/dotnet/core/)
==============================================================================
[command]C:\Windows\system32\chcp.com 65001
Active code page: 65001
[command]C:\agent\_work\_tool\dotnet\dotnet.exe publish C:\agent\_work\195\s\redacted.csproj --self-contained true --runtime win-x64 --configuration release --output C:\agent\_work\195\a\redacted
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for C:\agent\_work\195\s\redacted.csproj...
  Restore completed in 40.71 ms for C:\agent\_work\195\s\redacted.csproj.
  Restore completed in 0.51 ms for C:\agent\_work\195\s\redacted.csproj.
  Restore completed in 1.17 ms for C:\agent\_work\195\s\redacted.csproj.
  Restoring packages for C:\agent\_work\195\s\redacted.csproj...
C:\agent\_work\_tool\dotnet\sdk\2.2.105\NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/redacted/_packaging/redacted/nuget/v3/index.json. [C:\agent\_work\195\s\redacted.csproj]
C:\agent\_work\_tool\dotnet\sdk\2.2.105\NuGet.targets(114,5): error :   Response status code does not indicate success: 401 (Unauthorized). [C:\agent\_work\195\s\redacted.csproj]
##[error]Error: The process 'C:\agent\_work\_tool\dotnet\dotnet.exe' failed with exit code 1
##[error]Dotnet command failed with non-zero exit code on the following projects : C:\agent\_work\195\s\redacted.csproj
##[section]Finishing: Publish

1 个答案:

答案 0 :(得分:5)

  

错误:响应状态代码未指示成功:401   (未经授权)。

此错误是由Azure Devops中的错误引起的,为了对VSTS feed进行身份验证,Dotnet.exe仅支持dotnet restoredotnet nuget push命令。因此,请尝试先运行dotnet restore任务。

更新:

由于在运行dotnet restore之前已执行dotnet publish。身份验证问题应由dotnet publish任务引起。在执行--self-contained true时,这意味着除了本地拥有的默认文件外,它还会尝试从其他路径获取文件,包括您的私人提要。要访问私人供稿,它需要凭据。如果没有凭据,则私有供稿将拒绝获取请求。然后,可能会导致此错误。

而且,dotnet publish包含一个隐式 restore步骤,但是没有适当的系统凭据。因此,即使您已在较早的步骤中成功运行了dotnet restore,它也可能因未认证而失败,因为在上一个任务完成后将清除凭证。

您可以将--no-restore添加到参数中以避免隐式还原。有关更多详细信息,请查看以下文档:implicit restore that runs during publish