926

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

Arsen Khachaturyan
  • 7,904
  • 4
  • 42
  • 42
ryudice
  • 36,476
  • 32
  • 115
  • 163

8 Answers8

1130

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.

Arne Evertsson
  • 19,693
  • 20
  • 69
  • 84
PHeiberg
  • 29,411
  • 6
  • 59
  • 81
  • 1
    Explicitly getting a list of available packages: follow @Maciek 's response. You should also notice that when typing a space after the -Version argument, the NuGet Console in VS will show you some autocomplete list with the available versions for that package. – Xavier Decoster Jul 07 '11 at 21:02
  • 20
    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. – Bart Verkoeijen Feb 12 '12 at 10:27
  • 56
    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**. – Jonathan Moffatt Oct 11 '11 at 23:54
  • OR **View | Other Windows | Package Manager Console** =] – Leniel Maccaferri Feb 02 '12 at 15:46
  • 2
    @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... – Jesse Webb Jan 04 '13 at 20:14
  • 3
    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) – Curtis Yallop Jan 25 '13 at 21:49
  • 2
    `Get-Package -ListAvailable` does **not** list all available versions for me. – Roman Starkov Jun 26 '14 at 15:15
  • 2
    The `ListAvailable` argument in the `Get-Package` command has been deprecated. You should use `Find-Package -AllVersions` instead – Joseph Guadagno Jul 26 '16 at 21:41
  • @makhdumi : For big projects I only install packages from a local packages mirror. To add a package I open a small visual studio project and only install it there first . From the small project I copy the package to the local packages mirror and then update it in the bigger project. – Gregor Dec 08 '21 at 04:05
54

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.

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
37

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.

Morten Christiansen
  • 19,002
  • 22
  • 69
  • 94
  • 1
    Nice one... didn't think about that. I guess [NuGet Package Restore](https://docs.nuget.org/docs/reference/package-restore) has to be enabled for the solution though. – Leniel Maccaferri Apr 19 '14 at 18:10
  • 12
    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. – Jeroen Wiert Pluimers May 23 '14 at 08:12
26

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

NuGet 3 package manager UI

Yishai Galatzer
  • 8,791
  • 2
  • 32
  • 41
7

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.

Walt Ritscher
  • 6,977
  • 1
  • 28
  • 35
4

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
CodeFox
  • 3,321
  • 1
  • 29
  • 41
2

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

  1. Go to nuget.org
  2. Search package ex: Newton Json
  3. Click on result package name
  4. Click on Versions tab and download the version you want
  5. screenshot
user790049
  • 1,154
  • 1
  • 9
  • 21
0

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:

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

enter image description here

Good Luck :)

Anna Maule
  • 268
  • 1
  • 9