Visual Studio publish fails because of nuget authorization and works after successfull manual msbuild publish

Hello,
i was trying to publish a .net 6 project as self-contained with the following publish profile:
This resulted in the following error message:
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
I then tried several steps found on the internet to solve this including removing all kinds of Nuget account information or Nuget feeds to get VS to let me reenter the credentials again. All without success.
I then tried to run msbuild with the following command:
MSBuild.exe /target:publish /p:NuGetInteractive="true" /p:PublishDir="(targetDir)" /p:PublishProfile="(PathToProject)\Properties\PublishProfiles\FolderProfile.pubxml"
This did not work because of error NETSDK1047. We have no runtime identifier in the csproj, just the targetframework "net6" which seems to be a problem for msbuild. After adding the RuntimeIdentifier from the PublishProfile in our csproj and running dotnet restore the msbuild publish started working because Nuget added the runtime-information to the project.assets.json file.
The interesting thing is that after i could build successfully via cmd and msbuild one time the publish in Visual Studio started working again so it seems to be some Nuget credential cache related issue.
Any help or information regarding this is highly appreciated since multiple members of my team had this publish issue too.
@Jack J Jun Thanks for your reply to my question. I did indeed not try to clear the Nuget http cache yet so this could solve the issue.
The stackoverflow questions seems exactly related to my problem and there is also a link to the documentation page about how to clear local nuget caches which is also very helpful :)
@Julius Hackel, is any update? Have you tried my solution? Does it work for you? please feel free to me know if you have any issues.
@Jack J Jun It worked one time and VS opened a prompt to let me authenticate again after clearing the nuget caches.
Today i had the same problem again and the cache clearing method did not seem to work.
I have now installed the Credential Provider as a nuget plugin as written here:
https://learn.microsoft.com/en-us/nuget/consume-packages/consuming-packages-authenticated-feeds
Now if i call "dotnet restore --interactively" i can open a shown link in a browser to authenticate with a given code.
I am not sure if thats the way to go but it worked for me.
Sign in to comment