List all available versions of a specific package in NuGet Package Manager Console

PowershellNuget

Powershell Problem Overview


What NuGet PowerShell command will return a list of all versions of a specific package?

I have tried the following, but it only returns one version of NUnit along with a number of other (un)related packages, each having only one version.

Get-Package -Source https://go.microsoft.com/fwlink/?LinkID=206669 -ListAvailable -Filter NUnit -AllVersions

Note: I specify the source URI because we have our own internal package source as our default remote.

My understanding is that the -AllVersions switch should pull back every version of each matching package.

I can't seem to figure out:

  1. Am I doing it wrong?
  2. If not, are project maintainers (or someone else) removing older versions from the package source?
  3. If they are, why?

Powershell Solutions


Solution 1 - Powershell

Your source resolves to the version 1 of the feed which doesn't seem to work with -AllVersions (I filed an issue: https://github.com/NuGet/NuGetGallery/issues/563)

Using the V2 feed works for me:

get-package -ListAvailable -AllVersions -filter nunit -source https://nuget.org/api/v2/

But note that -filter is not for a specific package, but more like a search term.

As a workaround, I'd use tab autocomplete to get the versions list of a specific package:

install-package -source https://nuget.org/api/v2/ -id nunit -version <tab>

Solution 2 - Powershell

As of version 3.x, get-package -ListAvailable -AllVersions will still work, but will issue the following warning about imminent deprecation:

> 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'.

In addition, Find-Package supports an -ExactMatch switch which will avoid the wildcard matching issues that -Filter has:

Find-Package NUnit -AllVersions -ExactMatch -Source https://api.nuget.org/v3/index.json

Solution 3 - Powershell

To extend on the already provided solutions and address the follow-up questions by King King and JohnKoz, it is possible to get the full list of versions for a specific package as follows:

Find-Package -AllVersions -source https://nuget.org/api/v2/ Newtonsoft.Json -ExactMatch | foreach { $_.Versions } | Select-Object Version

The package Newtonsoft.Json is an example. Replace it as needed.

It works by first getting all versions for a single package (via -ExactMatch). This returns a package object that has a Versions property, which is an array of version objects. The foreach iterates over all these and the Select-Object ensures that each version object is output as a single line (by only selecting its main property).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAaron TorgersonView Question on Stackoverflow
Solution 1 - PowershellAlexandre DionView Answer on Stackoverflow
Solution 2 - PowershellStuartLCView Answer on Stackoverflow
Solution 3 - PowershellErwin BonsmaView Answer on Stackoverflow