Visual Studio publish fails because of nuget authorization and works after successfull manual msbuild publish
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
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.
@Julius Hackel, Welcome to Microsoft Q&A, first of all, what nuget source you used? The problem may be that some cache of Nuget credential was not cleaned. I recommend that you could clean the credential cache in provider tool directory and clean the http nuget cache also. After that, when first install the same nuget package, you need to give credential again(On my side, it will pop out login window.).
BTW, you could refer to the question to know more about the similar issue.
@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:
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