I am looking for some advice with updating nuget packages automatically on a pre-build event. I have already searched stack overflow which took me to posts dating six years back most of which does not apply anymore.
I did use the below command in our project:
"$(SolutionDir)nuget\Nuget.exe" update "$(ProjectDir)packages.config" -source "<PackageSource>" -id "<nuget package to update>"
This one did prompt me for a username password since this is within our organization. Not many users are interested in entering their creds even for the first time. Also this did not update the packages.config for some reason.
Is there away to force it? Or is there a better way to do this.
Actually, it works well in my side and it will update all the nuget packages from
packages.config
to the latest ones.To remove the authentication from the nuget package source on VS IDE and make it not happen on the next time, you should add its info into global
nuget.config
file so that it will not prompt next time. See this official document.Step
1) close VS, open the nuget.config from
C:\Users\xxx(current user)\AppData\Roaming\NuGet
add these:
2) Save the file and then restart VS to enable the new changes.
3) After that, you can remove the package source node in your command and it has already type in the global
nuget.config
file. Every time you run the command, it will first searchany info under global
nuget.config
file and if it has, you do not have to type under the command.Run this:
4) If it still does not update the
packages.config
, you can try these:delete the bin and obj folder, download the latest nuget.exe cli v5.7.0 and use the new version.
Besides, if you face any error messages under the update process, please share it with us.
This is a small demo about my test result: