'Publishing WPF application fails du to unauthorized .NuGet service index (Azure DevOps)

I want to publish one of my WPF applications (to a folder).
The app needs some NuGet packages that I published via Azure Devops. I signed in with Visual Studio with exactly the same account I use also in DevOps and for this reason it is no problem to install/remove the packages via the "Manage Packages for Solution".
Building and running my solution is also no problem.

But when I want to publish my solution I get an unauthorized message that I do not understand:

The plugin credential provider could not acquire credentials. Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`
4>Unable to load the service index for source https://pkgs.dev.azure.com/MyProjectName/_packaging/MyNuGetFeed/nuget/v3/index.json.

What could I try here? Why is VS having no issues to access the feed when I build and run the project locally but publishing is an issue?

Any proposals are welcome

Update:

This happens only if I choose the "Self contained" option. If I publish with "Framework independent" it works without problems.



Solution 1:[1]

I got a similar error on Teamcity:

When I want to publish my wpf app, (on a website, with clickonce...)

The plugin credential provider could not acquire credentials. Authentication may require manual action. Consider re-running the command with --interactive for dotnet, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for NuGet

Inspirred by enter image description here your comment, I tried to switch to self-Contained (after looking for the Framework-independent ;-) option) and got this info:

Found conflicts between different versions of "System.Drawing.Common" that could not be resolved.
6>There was a conflict between 
  "System.Drawing.Common, Version=4.0.0.0, Culture=neutral, and 
  "System.Drawing.Common, Version=5.0.0.0, Culture=neutral, 
6>"System.Drawing.Common, Version=4.0.0.0, Culture=neutral, was chosen because it was primary and 
  "System.Drawing.Common, Version=5.0.0.0, Culture=neutral, was not.

Ahh different versions of underlying .NET used.... !

6> References which depend on 
   "System.Drawing.Common, Version=4.0.0.0, Culture=neutral, 
     [...nuget\packages\system.drawing.common\4.5.0\ref\netstandard2.0\System.Drawing.Common.dll].
6>    ...nuget\packages\system.drawing.common\4.5.0\ref\netstandard2.0\System.Drawing.Common.dll
6> Project file item includes which caused reference 
     "...nuget\packages\system.drawing.common\4.5.0\ref\netstandard2.0\System.Drawing.Common.dll".
6>    ...nuget\packages\system.drawing.common\4.5.0\ref\netstandard2.0\System.Drawing.Common.dll

6> References which depend on 
"System.Drawing.Common, Version=5.0.0.0, Culture=neutral, 
     [].
6>  ...Release\net5.0-windows\xyz.dll
6> Project file item includes which caused reference 
   "...Release\net5.0-windows\xyz.dll".
6>  ...Release\net5.0-windows\xyz.dll

The xyz project or one of the nugets it relies on causes the problem ;-) (i.e. uses .net in a different version)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kfn