ChatGPT解决这个技术问题 Extra ChatGPT

Download old version of package with NuGet

Is there a way to download a previous version of a package with NuGet, not the latest one?


A
Arne Evertsson

Bring up the Package Manager Console in Visual Studio - it's in Tools / NuGet Package Manager / Package Manager Console. Then run the Install-Package command:

Install-Package Common.Logging -Version 1.2.0

See the command reference for details.

Edit: In order to list versions of a package you can use the Get-Package command with the remote argument and a filter:

Get-Package -ListAvailable -Filter Common.Logging -AllVersions

By pressing tab after the version option in the Install-Package command, you get a list of the latest available versions.


For the benefit of those who have been using Nuget for a while but never done anything with it from the command line: To run the powershell commands that PHeiberg mentions you will want to bring up the Package Manager Console in Visual Studio - it's in Tools|Library Package Manager|Package Manager Console.
This command should also be available via the UI. Now if a publisher has a beta version, you can only get that latest version, which is sometimes unstable.
@bgever - Most publishers create Prereleases for beta packages which are not considered the "Latest" in the GUI. As long as the publisher uses versioning correctly, the latest version should always be a stable one. That doesn't mean it won't have bugs however...
Dependency info and examining what other properties are available: Get-Package -ListAvailable [-Source X] -Filter Common.Logging -AllVersions | select version, dependencies (or '| get-member' to see all the properties)
Get-Package -ListAvailable does not list all available versions for me.
C
Colonel Panic

Browse to its page in the package index, eg. http://www.nuget.org/packages/Newtonsoft.Json/4.0.5

Then follow the install instructions given:

Install-Package Newtonsoft.Json -Version 4.0.5

Alternatively to download the .nupkg file, follow the 'Download' link eg. https://www.nuget.org/api/v2/package/Newtonsoft.Json/4.0.5

Obsolete: install my Chrome extension Nutake which inserts a download link.


M
Morten Christiansen

Another option is to change the version number in the packages.config file. This will cause NuGet to download the dlls for that version the next time you build.


Nice one... didn't think about that. I guess NuGet Package Restore has to be enabled for the solution though.
This isn't enough to also change the assembly reference automagically. What works though (if you have at lease two assemblies in your solution) is this: 1. make sure one assembly references the package, 2. edit the correct version in packages.config, 3. manage the NuGet packages on the solution, 3a. add the package to another project, removing it from the original project, and confirm this, 3b. reverse 3a and confirm. Step 3a will add the correct assembly reference to another project and remove it from the original. Step 3b will add the correct assembly reference to the original project.
Y
Yishai Galatzer

In NuGet 3.x (Visual Studio 2015) you can just select the version from the UI

https://i.stack.imgur.com/71hFv.png


Nice when it works but I've seen cases where not all old versions are listed there.
W
Walt Ritscher

In NuGet 3.0 the Get-Package command is deprecated and replaced with Find-Package command.

Find-Package Common.Logging -AllVersions

See the NuGet command reference docs for details.

This is the message shown if you try to use Get-Package in Visual Studio 2015.

This Command/Parameter combination has been deprecated and will be removed
in the next release. Please consider using the new command that replaces it: 
'Find-Package [-Id] -AllVersions'

Or as @Yishai said, you can use the version number dropdown in the NuGet screen in Visual Studio.


C
CodeFox

As the original question does not state which NuGet frontend should be used, I would like to mention that NuGet 3.5 adds support for updating to a specific version via the command line client (which works for downgrades, too):

NuGet.exe update Common.Logging -Version 1.2.0

u
user790049

I landed on this page but my requirement is different, I wanted to download old version of .nupkg file instead of downloading from VS2019 - to get old version of .nupkg

Go to nuget.org Search package ex: Newton Json Click on result package name Click on Versions tab and download the version you want


A
Anna Maule

By using the Nuget Package Manager UI as mentioned above it helps to uninstall the nuget package first. I always have problems when going back on a nuget package version if I don't uninstall first. Some references are not cleaned properly. So I suggest the following workflow when installing an old nuget package through the Nuget Package Manager:

Selected your nuget server / source Find and select the nuget package your want to install an older version Uninstall current version Click on the install drop-down > Select older version > Click Install

https://i.stack.imgur.com/9GPwB.png

Good Luck :)