You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Package Manager Consolelets you use [NuGet PowerShell commands](../tools/powershell-reference.md) to find, install, uninstall, and update NuGet packages. The Console is built into Visual Studio on Windows, version 2012 and later; it is not presently available with Visual Studio for Mac. The equivalent commands, however, are available through the [NuGet CLI](nuget-exe-CLI-reference.md).
33
+
The NuGet Package Manager Console, which is build into Visual Studio version 2012 and later, lets you use [NuGet PowerShell commands](../tools/powershell-reference.md) to find, install, uninstall, and update NuGet packages. Using the console is necessary in cases where the Package Manager UI does not provide a way to perform an operation.
34
34
35
-
> [!Note]
36
-
> If you're missing the NuGet Package Manager in Visual Studio 2015, check **Tools > Extensions and Updates...** and search for the NuGet Package Manager extension. If you're unable to use the extensions installer in Visual Studio, you can download the extension directly from [https://dist.nuget.org/index.html](https://dist.nuget.org/index.html).
37
-
>
38
-
> In Visual Studio 2017, NuGet and the NuGet Package Manager are automatically installed when you select any .NET-related workloads; you can also install it individually by checking the **Individual components > Code tools > NuGet package manager** option in the Visual Studio 2017 installer.)
39
-
40
-
Using the Console is necessary in cases where the Package Manager UI does not provide a way to perform an operation. Note, however, that all operations can be done with the [NuGet CLI](../tools/nuget-exe-cli-reference.md).
41
-
42
-
In all cases, you open the Console in Visual Studio through the **Tools > NuGet Package Manager > Package Manager Console** command.
43
-
44
-
At the top of the pane you can select the desired package source, manage sources (by clicking the gear icon), and select the default project to which commands will be applied:
You can override these settings with most commands by using the `-Source` and `-ProjectName` options.
35
+
All operations that are available in the console can also be done with the [NuGet CLI](../tools/nuget-exe-cli-reference.md). However, console commands operate within the context of Visual Studio and often accomplish more than their equivalent CLI commands. For example, installing a package through the console adds a reference to the project whereas the CLI command does not. For this reason, developers working in Visual Studio typically prefer using the console to the CLI.
49
36
50
37
In this topic:
51
38
39
+
-[Availability of the console](#availability-of-the-console)
40
+
-[Opening the console](#opening-the-console)
52
41
-[Finding a package](#finding-a-package)
53
42
-[Installing a package](#installing-a-package)
54
43
-[Uninstalling a package](#uninstalling-a-package)
55
44
-[Updating a package](#updating-a-package)
56
45
-[Extending the Package Manager Console](#extending-the-package-manager-console)
57
46
-[Setting up a NuGet PowerShell profile](#setting-up-a-nuget-powershell-profile)
58
47
48
+
## Availability of the console
49
+
50
+
In Visual Studio 2017, NuGet and the NuGet Package Manager are automatically installed when you select any .NET-related workloads; you can also install it individually by checking the **Individual components > Code tools > NuGet package manager** option in the Visual Studio 2017 installer.
51
+
52
+
Also, if you're missing the NuGet Package Manager in Visual Studio 2015 and earlier, check **Tools > Extensions and Updates...** and search for the NuGet Package Manager extension. If you're unable to use the extensions installer in Visual Studio, you can download the extension directly from [https://dist.nuget.org/index.html](https://dist.nuget.org/index.html).
53
+
54
+
The Package Manager Console it is not presently available with Visual Studio for Mac. The equivalent commands, however, are available through the [NuGet CLI](nuget-exe-CLI-reference.md). Visual Studio for Mac does have a UI managing NuGet packages. See [Including a NuGet package in your project](https://docs.microsoft.com/visualstudio/mac/nuget-walkthrough).
55
+
56
+
## Opening the console and console controls
57
+
58
+
Open the console in Visual Studio using the **Tools > NuGet Package Manager > Package Manager Console** command. The console is a Visual Studio window that can be arranged and positioned however you like (see [Customize window layouts in Visual Studio](https://docs.microsoft.com/visualstudio/ide/customizing-window-layouts-in-visual-studio)).
59
+
60
+
By default, console commands operate against a specific package source and project as set in the control at the top of the window:
61
+
62
+

63
+
64
+
Selecting a different package source and/or project changes those defaults for subsequent commands. To overrride these settings without changing the defaults, most commands support `-Source` and `-ProjectName` options.
65
+
66
+
To manage package sources, select the gear icon. This is a shortcut to the **Tools > Options > NuGet Package Manager > Package Sources** dialog box as described on the [Package Manager UI](Package-Manager-UI.md#package-sources) page. Also, the control to the right of the project selector clears the console's contents:
67
+
68
+

69
+
70
+
Finally, the rightmost button interrupts a long-running command. For example, running `Get-Package -ListAvailable -PageSize 500` lists the top 500 packages on the default source (such as nuget.org), which could take several minutes to run.
In the console, [`Get-Package -ListAvailable`](../tools/ps-ref-get-package.md)see all the packages available from the selected source. For nuget.org, the list will contain thousands of packages, so it's helpful to use the `-Filter` switch along with `-PageSize`. In NuGet 3.0 and later, you can instead use the [`Find-Package`](../tools/ps-ref-find-package.md) command that is better suited to this operation.
77
+
To see the packages available from the selected source, use the [`Get-Package -ListAvailable`](../tools/ps-ref-get-package.md)command. For nuget.org, the list contains thousands of packages, so it's helpful to use the `-Filter` switch along with `-PageSize` to limit the results. In NuGet 3+, you can instead use the [`Find-Package`](../tools/ps-ref-find-package.md) command that is better suited to this operation.
63
78
64
79
Examples:
65
80
66
81
```ps
67
-
# All versions of NuGet
82
+
# Show specific packages (all versions of NuGet)
68
83
Get-Package -ListAvailable -Filter elmah
69
84
Get-Package -ListAvailable -Filter Logging
70
85
71
86
# List all versions of packages matching the filter "jquery"
Once you know the identifier of the package you want to install use [`Install-Package`](../tools/ps-ref-install-package.md), such as `Install-Package elmah`.
106
+
Once you know the identifier of the package you want to install, use the [`Install-Package`](../tools/ps-ref-install-package.md) command. This command adds the package to the default project as specified in the console's project selector. To install the package into a different project, use the `-ProjectName` switch:
89
107
90
-
NuGet downloads the package from the specified package source and installs it in the default project of the solution, unless you specify another project using the `-ProjectName` switch.
108
+
```ps
109
+
# Add the Elmah package to the default project
110
+
Install-Package Elmah
111
+
112
+
# Add the Elmah package to a project named UtilitiesLib that is not the default
113
+
Install-Package Elmah -ProjectName UtilitiesLib
114
+
```
91
115
92
116
Installing a package performs the following actions:
93
117
94
-
- Display applicable license terms in the Console window with implied agreement. If you do not agree to the terms, you should uninstall the package immediately.
95
-
- Creates a `packages` folder (if needed) and copies package files into a subfolder within it.
96
-
- Adds references to the project, which subsequently appear in Solution Explorer
118
+
- Displays applicable license terms in the console window with implied agreement. If you do not agree to the terms, you should uninstall the package immediately.
119
+
- Adds a reference to the project in whatever reference format is in use. References subsequently appear in Solution Explorer and the applicable reference format file. Note, however, that with PackageReference, you need to save the project to see the changes in the project file directly.
120
+
- Caches the package in the project depending on the reference format in use:
121
+
-`packages.config`: creates a `packages` folder and copies package files into a subfolder within it.
122
+
-`project.json`: package is cached within `project.lock.json`
123
+
- PackageReference: package is cached within or `project.assets.json`
97
124
- Updates `app.config` and/or `web.config` if the package uses [source and config file transformations](../create-packages/source-and-config-file-transformations.md).
98
125
- Installs any dependencies if not already present in the project. This might update package versions in the process, as described in [Dependency Resolution](../consume-packages/dependency-resolution.md).
126
+
- Displays the package's readme file, if available, in a Visual Studio window.
99
127
128
+
> [!Tip]
129
+
> One of the primary advantages of installing packages with the `Install-Package` command in the console is that adds a reference to the project just as of you used the Package Manager UI. In contrast, the `nuget install` CLI command only downloads the package and does not automatically add a reference.
100
130
101
131
## Uninstalling a package
102
132
103
-
If you do not already know the name of the package you want to remove, use the [`Get-Package`](../tools/ps-ref-get-package.md) command with no parameters to see all of the currently-installed packages.
133
+
If you do not already know the name of the package you want to remove, use the [`Get-Package`](../tools/ps-ref-get-package.md) command with no arguments to see all of the packages currentlyinstalled in the default project.
104
134
105
135
To uninstall a package, use [`Uninstall-Package`](../tools/ps-ref-uninstall-package.md) with the package ID, such as `Uninstall-Package jQuery`.
106
136
107
137
Uninstalling a package performs the following actions:
108
138
109
-
-References to the package no longer appear in the **Reference** or **Bin** folders in Solution Explorer. (You might need to rebuild the project to see it removed from the **Bin** folder.)
110
-
-The folder for the package is removed from the `packages` folder; the `packages` folder itself is deleted if no packages remain.
111
-
-Any changes made to `app.config` or `web.config` when the package was installed are removed.
112
-
-If other packages were installed because they were dependencies of the package that was removed, and if no remaining packages use those dependencies, the dependency packages are also removed.
139
+
-Removes references to the package from the project (and whatever reference format is in use). References no longer appear in Solution Explorer. (You might need to rebuild the project to see it removed from the **Bin** folder.)
140
+
-Removes the package from the project cache (`packages` folder, `project.lock.json`, or `project.assets.json`)
141
+
-Reverses any changes made to `app.config` or `web.config` when the package was installed.
142
+
-Removes previously-installed dependencies if no remaining packages use those dependencies.
113
143
144
+
> [!Tip]
145
+
> Like `Install-Package`, the `Uninstall-Package` command has the benefit of managing references in the project, unlike the `nuget uninstall` CLI command.
114
146
115
147
## Updating a package
116
148
117
149
The [`Get-Package -updates`](../tools/ps-ref-get-package.md) command checks if there are newer versions available for any installed packages.
118
150
119
-
To update a package, use [`Update-Package`](../tools/ps-ref-update-package.md) with the package ID, such as `Update-Package jQuery`.
151
+
To update a package, use [`Update-Package`](../tools/ps-ref-update-package.md) with the package ID, such as `Update-Package jQuery`.
120
152
153
+
To update all packages in the project, use `Update-Package -ProjectName <project_name>`; to update all packages in the solution, use `Update-Package` with no arguments.
121
154
122
155
## Extending the Package Manager Console
123
156
124
-
Some packages install new commands for the Console. For example, `MvcScaffolding`, creates commands, such as `Scaffold` shown below, to generate ASP.NET MVC controllers and views:
157
+
Some packages install new commands for the console. For example, `MvcScaffolding` creates commands like `Scaffold` shown below, which generates ASP.NET MVC controllers and views:
125
158
126
159

127
160
128
161
129
162
## Setting up a NuGet PowerShell Profile
130
163
131
-
A PowerShell profile lets you make commonly-used commands available wherever you use PowerShell. NuGet supports a NuGetspecific profile typically located at:
164
+
A PowerShell profile lets you make commonly-used commands available wherever you use PowerShell. NuGet supports a NuGet-specific profile typically found at the following location:
0 commit comments