Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling self-contained causes dotnet publish to fail with private NuGet

Enabling a self-contained publish causes an error when authenticating with a private NuGet feed. Without "--self-contained true" everything runs fine, with it the error below appears. What can I do to resolve this?

##[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://learn.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
like image 592
bdebaere Avatar asked Jul 29 '19 12:07

bdebaere


1 Answers

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

This error is caused by that in Azure Devops, for authenticating to VSTS feed, the Dotnet.exe only supports dotnet restore and dotnet nuget push commands. So, try running dotnet restore task first.

Update:

Since you have executed the dotnet restore before running dotnet publish. The auth issue should be caused by the dotnet publish task. While you execute --self-contained true, this means that except for the default files which you have locally, it also tries to get files from the other path including your private feed. For accessing private feed, it needs credential. Without credential, the private feed will refuse the get request. And then, it may cause this error.

And also, dotnet publish include an implicit restore step but will not have the system credentials in place. So, even if you have run dotnet restore successfully in the earlier step, it can also fail with non-authenticated because the credential is cleaned up after the previous task is finished.

You can add --no-restore to the arguments to avoid implicit restore. For more details, please check this doc: implicit restore that runs during publish.

like image 65
Mengdi Liang Avatar answered Nov 05 '22 22:11

Mengdi Liang