Install and manage packages in Visual Studio using the NuGet Package Manager (original) (raw)

The NuGet Package Manager UI in Microsoft Visual Studio for Windows allows you to easily install, uninstall, and update NuGet packages in projects and solutions.

The article is for Windows users only. If you're using Visual Studio for Mac, see Including a NuGet package in your project.

Prerequisites

Find and install a package

To find and install a NuGet package with Visual Studio, follow these steps:

  1. Load a project in Solution Explorer, and then select Project > Manage NuGet Packages.
    The NuGet Package Manager window opens.
  2. Select the Browse tab to display packages by popularity from the currently selected source (see Package sources).
    • To search for a specific package, use the search box on the upper left.
    • Abbreviated information may be shown beside each package ID to help identify the correct package, and varies based on the selected package source(s). Examples include package download count, author, or owner profile hyperlinks.
      Note
      In Visual Studio 17.11 and higher, package owners are shown as profile hyperlinks when supported by the selected package source. Package ownership is defined by the package source. For example, see Manage package owners on nuget.org.
      In Visual Studio 17.10 and earlier, the package author metadata is shown, which appears as plain-text. For more information, see Authors package metadata.
  3. In the right pane, select a Version from the dropdown list. If you want to include prerelease versions in the Version list, select Include prerelease.
  4. To install the NuGet package, select Install. You might be asked to accept license terms or prompted to verify the installation.
    Visual Studio installs the package and its dependencies in the project. When installation is complete, the added packages appear on the Installed tab. You can also find packages in the Dependencies > Packages node of your project in Solution Explorer. After you install a package, you can refer to it in the project with a using statement.
  5. (Optional) NuGet has two formats in which a project can use packages: PackageReference and packages.config. To set the default format, select Tools > Options, expand NuGet Package Manager, select General, and then choose the Default package management format. For more information, see Choose default package management format.

Uninstall a package

To uninstall a NuGet package, follow these steps:

  1. Load a project in Solution Explorer, select Project > Manage NuGet Packages, and then select the Installed tab.
  2. Select the package to uninstall in the left pane (use the Search box to find it, if necessary), and then select Uninstall from the right pane.
    Screenshot showing the NuGet Package Manager with a package selected and its Uninstall button highlighted.

Update a package

To update a NuGet package, follow these steps:

  1. Load a project in Solution Explorer, and then select Project > Manage NuGet Packages. For website projects, select the Bin folder first.
  2. Select the Updates tab to see packages that have available updates from the selected Package source. Select Include prerelease to include prerelease packages in the update list.
  3. Select the package to update. On the right pane, select the desired Version from the dropdown list, and then select Update.
    Screenshot showing the NuGet Package Manager with a package selected and its Update button highlighted.
  4. For some packages, the Update button is disabled and the following message appears: Implicitly referenced by an SDK. To update the package, update the SDK to which it belongs. This message indicates that the package is part of a larger framework or SDK and can't be updated independently. Such packages are internally marked with <IsImplicitlyDefined>True</IsImplicitlyDefined>. For example, Microsoft.NETCore.App is part of the .NET Core SDK, and the package version is different than the version of the runtime framework used by the application. To download a new version of the .NET Core, update your .NET Core installation. For more information, see .NET Core metapackages and versioning. This scenario applies to the following commonly used packages:
    • Microsoft.AspNetCore.All
    • Microsoft.AspNetCore.App
    • Microsoft.NETCore.App
    • NETStandard.Library
      Screenshot showing a NuGet package with the Update button disabled.
  5. To update multiple packages to their latest versions, choose them in the NuGet package list, and then select Update.
  6. You can also update an individual package from the Installed tab. For this case, you can also select a Version and the Include prerelease option.

Manage packages for the solution

Managing packages for a solution is a convenient means to work with multiple projects simultaneously:

  1. Select a solution in Solution Manager, and then select Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
  2. In the Manage NuGet Packages for Solution window, select the projects that are affected by the operations.
    Screenshot showing the Manage Packages for Solution window with multiple projects selected.

Consolidate tab

Developers typically consider it bad practice to use different versions of the same NuGet package across different projects in the same solution. Visual Studio allows you to use a common version for your NuGet packages. To do so, use the Consolidate tab of the NuGet Package Manager window to discover where packages with distinct version numbers are used by different projects in the solution.

Screenshot showing the Manage Packages for Solution window with the Consolidate tab selected.

In this example, the ClassLibrary1 project is using EntityFramework 6.2.0, whereas ConsoleApp1 is using EntityFramework 6.1.0. To consolidate package versions, follow these steps:

  1. From the Consolidate tab, select the projects to update in the project list.
  2. Select the version to use for all these projects in the Version list.
  3. Select Install.
    The NuGet Package Manager installs the selected package version into all the selected projects, after which the package no longer appears on the Consolidate tab.

Package sources

Visual Studio ignores the order of package sources, and uses the package from whichever source is the first to respond to a request. For more information, see Restore packages. For information about how to load a package from a specific source, see Package source mapping.

  1. To change the source from which Visual Studio loads package metadata, select a source from the Package source selector.
    Screenshot showing the Package source selector highlighted.
  2. To manage your package sources, select the Settings icon or select Tools > Options.
    Screenshot showing the Package source settings icon highlighted.
  3. To manage NuGet package sources, see NuGet Options in Visual Studio.

NuGet Package Manager Options control

When you select a package, the NuGet Package Manager displays an expandable Options control below the Version selector. For most project types, only the Show preview window option is provided.

Screenshot showing the NuGet Package manager Options control expanded.

The following sections explain the available options.

Install and update options

These options are available only for certain project types:

Uninstall options

These options are available only for certain project types:

See also

For more information about NuGet, see the following articles: