Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet.exe command-line update to specific version

Tags:

.net

nuget

The NuGet Update-Package PowerShell command which can be run from inside Visual Studio has supported for a -Version flag which allows updating to a specific version of a package.

It is a big limitation for our build server workflow that the nuget.exe update command doesn't support this scenario, and I am thinking of two options:

  1. Modify the nuget.exe command line tool source code. This doesn't seem hard, there already seems to be support for calling UpdatePackageReference with a version specification, which is used by the -Safe switch.

  2. Write a command-line extension (e.g. as explained here), similar to NuGet.Analyze, that adds a version-specific update command to nuget.exe. From what I can tell, though, this will require duplicating most of the code in the UpdateCommand class, is most of its key methods are internal or private.

Does anyone with more experience with the nuget.exe command-line tool (or writing extensions for it) have more insight into what the right route would be, or if there is an alternative solution?

like image 630
rikoe Avatar asked Apr 14 '26 12:04

rikoe


1 Answers

I ended up trying the first option, and it was easier than I initially thought. There is already support for updating to a specific version in the API, and I simply had to add a -Version option for the command line tool, and invoke it if specified.

I have created a fork of NuGet 2.8.2 with the change applied here: https://github.com/rikoe/nuget/tree/2.8.2.

I will try to submit a pull request to get it added to a future version of NuGet.

like image 60
rikoe Avatar answered Apr 17 '26 02:04

rikoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!