如何列出所有已安装的 NuGet 软件包?

如何列出所有本地安装的 NuGet 包?

有没有一个相当于 RPM -qa的 NuGet?在 巧克力味的中有 chocolatey list -localonly,但是在我的生活中我无法找到与这个命令等价的 NuGet。

88736 次浏览

In the NuGet Package Manager Console, enter the following command:

Get-Package | Format-Table -AutoSize

This will either print out a list of installed packages, or if none are present write the following line to the console:

PM> Get-Package
No packages installed.

For more details, have a look at the NuGet PowerShell Reference.

In Visual Studio,

  • go to the Project or Solution in question
  • right click, Manage NuGet Packages...
  • on the left, you will see 'Installed Packages'
  • click on this and you will see the list
Get-Package -ProjectName "Your.Project.Name"

Will show the packages for the specified project.

See also: Package Manager Console PowerShell Reference

Note that each project will have a packages.config file which is used to track installed packages. If this is altered (specifically if you alter it backwards), the projects may not automatically download the correct package version. In that case, make a note of the packages required and do a uninstall-package, followed by a install-package for each.

Also, backups are your friend! ;)

If you just do

Get-Package

it will list the packages and where they are referenced. It will list the same packages over and over again if you have them referenced many times. If you want to get a clean list of all packages installed in the solution you can do

Get-Package | select -Unique Id, Versions

How do I list all installed NuGet Packages?

Assuming that NuGet is properly installed

Right click Project node and click Manage NuGet Packages

Right click Project node

See installed packages list

See installed packages

In addition to all of the given answers, there is also a clean listing in XML format of all installed packages in your Visual Studio project root folder: packages.config:

Enter image description here

Answer to "Is there a way to do this using nuget.exe? – bitbonk":

nuget list -Source C:/packages

Where C:/packages is a path to your local repository.

Answer to "Is there a way to do this using nuget.exe?" – bitbonk

Based on the answer from jstar above. I used \ instead of / which fits more to the Windows environment where nuget is at home. My edit of the answer was rejected so I post my own.

nuget list -Source c:\code\packages

Where c:\code is a path to your local code-repository. The packages folder is on the same level like your solution-file (*.sln).

If you have the .NET Core runtime installed, you can use the dotnet list package command in the .NET Core CLI tools to fetch installed packages for a given solution or project. Use it like so from the Windows command line:

dotnet list "C:\Source\MySolution\MySolution.sln" package

It works on both .NET Framework and .NET Core projects.

Note: For this command to work, the solution must use the new NuGet PackageReference format for referencing NuGet packages. Migration is as easy as right-clicking packages.config, and clicking "Migrate packages.config to PackageReference...", then restoring packages by building the solution.