Skip to content

How to Manage NuGet Package by Using the Package Manager Console (CLI)

I - Using the Package Manager Console in Visual Studio

II - Finding a Package in the NuGet Package Manager Console

III - Installing a Package Using the NuGet Console

IV - Updating Packages Using the NuGet Console

V - Uninstalling a Package Using the NuGet Console

Before using the NuGet Package Manager to install, update, or remove packages, make sure you have added the appropriate package source in Visual Studio. For more information, please see this document: How to add and manage package resource

I - Using the Package Manager Console in Visual Studio

  1. To open the Package Manager Console, go to Tools > NuGet Package Manager > Package Manager Console from the top menu.

  2. At the top of the console window, you'll find controls for selecting both the package source and the target project.

    • These determine where commands are executed by default.

💡 Changing the selected package source or project updates the defaults for all upcoming commands. If you only want to override them for a single command, most NuGet Console commands support the -Source and -ProjectName parameters.

Package Manager Console Overview

  1. To manage your package sources, click the gear (⚙️) icon next to the source selector.
    • This opens the Tools > Options > NuGet Package Manager > Package Sources dialog box.
    • The button beside the project selector clears the console window.

Package Sources Settings

  1. The button on the far right stops a command that's taking too long to complete.

    For example, running:

    Get-Package -ListAvailable -PageSize 500

    will display the top 500 available packages from the default source (like NuGet Gallery), which may take several minutes to finish.

Stop Command Button

II - Finding a Package in the NuGet Package Manager Console

  1. To search for a package from the default source, use the Find-Package command:
Find-Package
  1. To find and list packages that contain specific keywords, run:
Find-Package <keyword1>
Find-Package <keyword2>
  1. To search for packages whose names start with a particular string, use the -StartWith parameter:
Find-Package <string> -StartWith
  1. By default, Find-Package displays up to 20 results. To show more, use the -First option. For example, to list the first 100 matching packages:
Find-Package <keyword> -First 100
  1. To view all available versions of a specific package, add the -AllVersions and -ExactMatch parameters:
Find-Package <PackageName> -AllVersions -ExactMatch

III - Installing a Package Using the NuGet Console

1.To install a package into your default project, use the following command in the Package Manager Console:

Install-Package <PackageName>

2.By default, the package is installed into the project currently selected as the default in the console's project dropdown.

To install it into a different project, use the -ProjectName option:

Install-Package <packageName> -ProjectName <projectName>

IV - Updating Packages Using the NuGet Console

  1. To check for newer versions of any installed packages, use:
Get-Package -Updates
  1. To update a specific package to its latest available version, run:
Update-Package <PackageName>
  1. To update all packages within a single project, specify the project name:
Update-Package -ProjectName <ProjectName>
  1. To update every package in the entire solution, simply run:
Update-Package

Visual Studio will automatically download and apply the latest compatible versions of all referenced packages.

V - Uninstalling a Package Using the NuGet Console

  1. To remove a package from your default project, run the following command in the Package Manager Console:
Uninstall-Package <PackageName>

If you're unsure of the exact package name, use:

Get-Package

to list all packages currently installed in the default project.

  1. To remove a package along with all its unused dependencies, use:
Uninstall-Package <PackageName> -RemoveDependencies
  1. To force removal of a package even if other packages depend on it, use:
Uninstall-Package <PackageName> -Force