简体   繁体   中英

How to install a specific version of nuget?

I'm troubleshooting some issues with specific versions of nuget and msbuild, hence need for downgrading of nuget versions:

Build failures with Mono 5.14.0.177, msbuild 15.0, nuget 4.7.1 on Travis CI, but not reproducible in VirtualBox

Nuget can be updated to latest version with this command:

nuget update -self

However installing a specific version of nuget seems to be unsupported, this still install the latest version of nuget:

nuget update -self -Version 4.6.2

And this fails with nuget not found error:

nuget install nuget -Version 4.6.2

https://docs.microsoft.com/en-us/nuget/tools/cli-ref-install

https://docs.microsoft.com/en-us/nuget/tools/cli-ref-update


EDIT:

Looking at nuget source code the developers made an assumption that update should always happen to the latest version:

https://github.com/NuGet/NuGet.Client/blob/3803820961f4d61c06d07b179dab1d0439ec0d91/src/NuGet.Clients/NuGet.CommandLine/Common/SelfUpdater.cs#L85

// Check to see if an update is needed
if (package == null || version >= package.Version)

Very sad decision, Microsoft! Hence submitted a PR and it was rejected:

https://github.com/NuGet/NuGet.Client/pull/2422

How to install a specific version of nuget?

According to the document NuGet CLI reference :

Each download is the nuget.exe file directly. Instruct your browser to save the file to a folder of your choice. The file is not an installer ; you won't see anything if you run it directly from the browser.

We could to know, NuGet.exe is not an installer. You can just download the version what you want from the nuget.org , then replace the one on the local disk.

Although NuGet team provide the command line nuget update -self , which can be used to update the nuget.exe to the latest version, just like what have you said, nuget update command not support update nuget.exe for a specify version. So, I think your PR is reasonable, but it should be at a low priority. Because we can update nuget.exe by downloading manually.

Hope this clear and helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM