Skip to content

Commit 777b631

Browse files
author
Kraig Brockschmidt
committed
Overhauling PM Console (for CSAT)
1 parent 6610e52 commit 777b631

File tree

5 files changed

+80
-38
lines changed

5 files changed

+80
-38
lines changed

docs/Tools/Package-Manager-Console.md

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: NuGet Package Manager Console Guide | Microsoft Docs
55
author: kraigb
66
hms.author: kraigb
77
manager: ghogen
8-
ms.date: 6/13/2017
8+
ms.date: 7/17/2017
99
ms.topic: article
1010
ms.prod: nuget
1111
#ms.service:
@@ -30,49 +30,67 @@ ms.reviewer:
3030

3131
# Package Manager Console
3232

33-
The Package Manager Console lets 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.
3434

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:
45-
46-
![Package Manager Console controls](media/PackageManagerConsoleControls.png)
47-
48-
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.
4936

5037
In this topic:
5138

39+
- [Availability of the console](#availability-of-the-console)
40+
- [Opening the console](#opening-the-console)
5241
- [Finding a package](#finding-a-package)
5342
- [Installing a package](#installing-a-package)
5443
- [Uninstalling a package](#uninstalling-a-package)
5544
- [Updating a package](#updating-a-package)
5645
- [Extending the Package Manager Console](#extending-the-package-manager-console)
5746
- [Setting up a NuGet PowerShell profile](#setting-up-a-nuget-powershell-profile)
5847

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+
![Package Manager Console controls for package source and project](media/PackageManagerConsoleControls1.png)
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+
![Package Manager Console settings and clear controls](media/PackageManagerConsoleControls2.png)
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.
71+
72+
![Package Manager Console stop control](media/PackageManagerConsoleControls3.png)
73+
5974

6075
## Finding a package
6176

62-
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.
6378

6479
Examples:
6580

6681
```ps
67-
# All versions of NuGet
82+
# Show specific packages (all versions of NuGet)
6883
Get-Package -ListAvailable -Filter elmah
6984
Get-Package -ListAvailable -Filter Logging
7085
7186
# List all versions of packages matching the filter "jquery"
7287
Get-Package -ListAvailable -Filter jquery -AllVersions
7388
89+
# List the top 100 packages
90+
Get-Package -ListAvailable -PageSize 100
91+
7492
75-
# NuGet 3.0+
93+
# Find-Package in NuGet 3+ is more efficient than Get-Package
7694
Find-Package elmah
7795
Find-Package Logging
7896
@@ -85,56 +103,75 @@ Find-Package jquery -AllVersions -ExactMatch
85103

86104
## Installing a package
87105

88-
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:
89107

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+
```
91115

92116
Installing a package performs the following actions:
93117

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`
97124
- Updates `app.config` and/or `web.config` if the package uses [source and config file transformations](../create-packages/source-and-config-file-transformations.md).
98125
- 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.
99127

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.
100130
101131
## Uninstalling a package
102132

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 currently installed in the default project.
104134

105135
To uninstall a package, use [`Uninstall-Package`](../tools/ps-ref-uninstall-package.md) with the package ID, such as `Uninstall-Package jQuery`.
106136

107137
Uninstalling a package performs the following actions:
108138

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.
113143

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.
114146
115147
## Updating a package
116148

117149
The [`Get-Package -updates`](../tools/ps-ref-get-package.md) command checks if there are newer versions available for any installed packages.
118150

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`.
120152

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.
121154

122155
## Extending the Package Manager Console
123156

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:
125158

126159
![Installing and using MvcScaffold](media/PackageManagerConsoleInstall.png)
127160

128161

129162
## Setting up a NuGet PowerShell Profile
130163

131-
A PowerShell profile lets you make commonly-used commands available wherever you use PowerShell. NuGet supports a NuGet specific 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:
132165

133-
%UserProfile%\Documents\WindowsPowerShell\NuGet_profile.ps1
166+
```
167+
%UserProfile%\Documents\WindowsPowerShell\NuGet_profile.ps1
168+
```
134169

135-
To find the profile file, type `$profile` in the Console:
170+
To find the profile, type `$profile` in the console:
136171

137-
$profile
138-
C:\Users\<user>\Documents\WindowsPowerShell\NuGet_profile.ps1
172+
```ps
173+
$profile
174+
C:\Users\<user>\Documents\WindowsPowerShell\NuGet_profile.ps1
175+
```
139176

140177
For more details, refer to [Windows PowerShell Profiles](https://technet.microsoft.com/library/bb613488.aspx).
3.31 KB
Loading
3.27 KB
Loading
6.52 KB
Loading

docs/index.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
---
32
layout: HubPage
43

@@ -17,7 +16,7 @@ keywords:
1716
author: kraigb
1817
ms.author: kraigb
1918
manager: ghogen
20-
ms.date: 1/9/2017
19+
ms.date: 7/17/2017
2120
ms.topic: hubpage
2221
ms.prod: nuget
2322
#ms.service:
@@ -192,6 +191,12 @@ ms.reviewer:
192191
<p>Detailed release notes for every version of NuGet back to the beginning.</p>
193192
</a>
194193
</li>
194+
<li class="column column-third">
195+
<a href="https://github.com/NuGet">
196+
<h3>GitHub Repositories</h3>
197+
<p>NuGet is entirely open source, including the NuGet client, server, documentation, and more.</p>
198+
</a>
199+
</li>
195200
</ul>
196201
</section>
197202
</li>

0 commit comments

Comments
 (0)