- 7 minutes to read
The NuGet Package Manager UI in Microsoft Visual Studio for Windows lets you 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, seeInclude a NuGet package in your project.
Install Visual Studio 2022 for Windows with any .NET related workload.
You can install the Community 2022 edition for free fromvisualstudio.microsoft.com, or use the Professional or Enterprise edition.
Visual Studio 2017 and later versions automatically include the NuGet Package Manager when a .NET related workload is installed. To install them individually in the Visual Studio Installer, select theindividual componentstab and then selectNuGet Package Managerlowcode tools.
For Visual Studio 2015, if NuGet Package Manager is missing, checkTools>Extensions and updatesand look for theNuGet Package Managerextension. If you cannot use the extension installer in Visual Studio, download the extension directly fromhttps://dist.nuget.org/index.html.
Sign up for a free account at nuget.orgif you don't already have one. You must register and confirm the account before you can upload a NuGet package.
Find and install a package
To find and install a NuGet package with Visual Studio, follow these steps:
Upload a project tosolution explorerand then selectProject>Manage NuGet Packages.
HeNuGet Package Managerwindow opens.
Select theTo browseto display packages by popularity of the currently selected source (seepackage sources). To search for a specific package, use the search box in the top left corner. Select a package from the list to display its information in the right pane, allowing you to select a version to install.
In the right pane, select aVersionin the drop-down list. If you want to include preview versions inVersionlist, selectinclude preview.
To install the NuGet package, selectinstall. You may be asked to accept the license terms or verify the installation.
Visual Studio installs the package and its dependencies into the project. When the installation is complete, the added packages will appear in theInstalledEyelash. You can also find packages ondependencies>packagesnode of your project insolution explorer. After installing a package, you can reference it in the project with a
(Optional) NuGet has two formats in which a project can use packages:package referenceypackages.config. To set the default format, selectTools>options, expandNuGet Package Manager, selectIn generaland then choose theStandard package management format. For more information, seeChoose default package management format.
uninstall a package
To uninstall a NuGet package, follow these steps:
Upload a project tosolution explorer, selectProject>Manage NuGet Packagesand then select theInstalledEyelash.
Select the package to uninstall in the left panel (use theTo search forto find it if necessary) and then selectuninstallfrom the right panel.
update a package
To update a NuGet package, follow these steps:
Upload a project tosolution explorerand then selectProject>Manage NuGet Packages. For website projects, select thePaper boxfolder first.
Select theupdatestab to see packages that have updates available for the selectedpackage source. selectinclude previewto include pre-release packages in the update list.
Select the package to upgrade. In the right pane, select the desiredVersionfrom the drop-down list and selectTo update.
For some packages, theTo updateThe button is disabled and the following message appears:Implicitly referenced by an SDK. To update the package, update the SDK it belongs to.This message indicates that the package is part of a larger SDK or framework and cannot be independently updated. These packages are internally marked with
<IsImplicitlyDefined>True</IsImplicitlyDefined>. For example,
Microsoft.NETCore.ApplicationIt's part of the .NET Core SDK and the package version is different from the runtime framework version used by the app. To download a new version of .NET Core,update your .NET Core installation. For more information, see.NET Core Releases and Metapackages. This scenario applies to the following commonly used packages:
To update multiple packages to their latest versions, choose them from the list of NuGet packages and selectTo update.
You can also upgrade an individual package fromInstalledEyelash. For this case, you can also select aVersionit's himinclude previewoption.
Manage packages for the solution
Managing packages for a solution is a convenient way to work with multiple projects simultaneously:
Select a solution fromsolutions managerand then selectTools>NuGet Package Manager>Manage NuGet packages for the solution.
NoManage NuGet packages for the solutionwindow, select the projects that are affected by the operations.
Developers often consider it bad practice to use different versions of the same NuGet package in different projects in the same solution. Visual Studio allows you to use a common version for your NuGet packages. For this, use theConsolidateguide ofNuGet Package Managerwindow to find out where packages with different version numbers are used by different projects in the solution.
In this example, the ClassLibrary1 project uses EntityFramework 6.2.0, while ConsoleApp1 uses EntityFramework 6.1.0. To consolidate package versions, follow these steps:
SinceConsolidatetab, select the projects to update from the list of projects.
Select the version to be used for all these projects in theVersionlist.
The NuGet Package Manager installs the selected package version in all selected projects, after which the package no longer appears in theConsolidateEyelash.
Visual Studio ignores the order of package sources and uses the source package that is the first to respond to a request. For more information, seerestore packages. For information on how to load a package from a specific source, seePacket Source Mapping.
To manage NuGet package sources, follow these steps:
To change the source from which Visual Studio loads package metadata, select a source from thepackage sourceselector.
To manage your package sources, select thesettingsicon or selectTools>options.
Nooptionswindow, expand theNuGet Package Managernode and selectpackage sources.
To add a font, select+, edit theName, enter the URL or path insourceand then selectTo update.
The font now appears in thepackage sourcethe drop-down list.
To change the origin of a package, select it, edit theNameysourcecheckboxes and selectTo update.
To disable a package's source, uncheck the box to the left of the name in the list.
To remove a package source, select it and then select thexbutton.
If the source of a package reappears after removing it, it can be listed at the computer or user level.NuGet.configfile. For the location of these files, seeCommon NuGet Settings. Remove the package source in the files by editing them manually or using thenuget fonts command.
NuGet package manager options control
When you select a package, the NuGet Package Manager displays an expandable windowoptionscontrol below theVersionselector. For most types of projects, just theshow preview windowoption is provided.
The following sections explain the available options.
Installation and update options
These options are only available for certain types of projects:
addictive behavior– This option configures how NuGet decides which versions of dependent packages to install. It has the following settings:
- ignore dependenciesbypasses the installation of dependencies, which often breaks the package being installed.
- lower[Default] installs the dependency with the minimum version number that meets the requirements of the chosen parent package.
- highest patchinstalls the version with the same major and minor version numbers, but the higher patch number. For example, if version 1.2.2 is specified, the latest version starting with 1.2 will be installed.
- bigger, smallerinstalls the version with the same major version number, but with the higher minor and patch number. If version 1.2.2 is specified, the latest version starting with 1 will be installed
- higherinstalls the latest available version of the package.
Conflict file action: This option specifies how NuGet should handle packages that already exist in the project or on the local machine. It has the following settings:
- Immediatetells NuGet to ask you if you want to keep or replace existing packages.
- ignore everythingtells NuGet to ignore replacing existing packages.
- overwrite alltells NuGet to replace existing packages.
These options are only available for certain types of projects:
remove dependencies: when selected, remove dependent packages if they are not referenced elsewhere in the project.
Force uninstall even if there are dependencies: when selected, uninstalls a package even if it is still referenced in the project. This option is often used in combination withremove dependenciesto remove a package and any dependencies it has installed. However, using this option can lead to broken references in the project. In that case, you may needreinstall these other packages.
- Install and use a NuGet package with Visual Studio
- Find more NuGet videos atCanal 9yYouTube.
For more information about NuGet, see the following articles:
- What is NuGet?
- Package consumption workflow
- Find and choose packages
- Package references in project files
- Install and use a package using the .NET CLI.