Package Manager Console Commands (v1.3)

The Package Manager Console lets you run PowerShell scripts from within Visual Studio and is the host for the PowerShell-based NuGet commands. The console includes a drop-down list that shows the available package sources (feeds) and a drop-down list that lets you specify the default project for project packages.

image

This topic provides a reference for PowerShell commands that you can use to manage NuGet packages in Visual Studio.

Get‑Package

Gets the set of packages that are available from the package source. By default, this command returns installed packages.

Argument Description
‑Source sourceUrlOrPath (Optional) Specifies the package source (feed). Typically this is the URL of an OData service or the path of a folder that contains a set of packages.
‑Updates (Optional) Lists packages that have an update available from the package source.
‑Remote (Optional) Lists packages that are available from the feed specified in the Package source list of the Package Manager Console window.
‑Filter filterSpecification (Optional) Specifies a filter that is used to narrow down the list of packages returned. Filtering applies to the package ID and description.

Sample Usage

The following example shows how to list all packages in the feed that is specified in the Package Source list.

PM> Get‑Package -Remote

Install‑Package

Installs a package and its dependencies into the project or the solution. For project packages, this installs the package and applies it to a specific project. Files are copied to the project, assembly references added, the app.config or web.config file is updated, etc.

Argument Description
‑Id packageName
(Required) Specifies the package to install. Including the ‑Id flag is optional, because the value for this flag is always the first parameter for this command.
‑IgnoreDependencies (Optional) Specifies that only this package (not its dependencies) is installed.
‑Project projectName (Optional) The project to install the package into. This option applies only to project packages. If a project is specified in the Default project list of the Package Manager Console window, this option is not required. If no default project is selected, this option is required.
‑Source sourceURL (Optional) Specifies the URL of the package to install. The default is to look in the feed to find the corresponding package URL.
‑Version versionNumber (Optional) Specifies the version of the package to install. The default is the latest version.

Sample Usage

The following example shows how to install the package that has the ID elmah.

PM> Install‑Package elmah

The following example shows how to install a package named my.pack that is in a local directory.

PM> Install‑Package my.pack ‑Source c:\my‑packages

Uninstall‑Package

Uninstalls a package. If other packages depend on this package, the command will fail unless the ‑Force option is specified.

Argument Description
‑Id packageName (Required) Specifies the package to uninstall. Including the -Id flag is optional, because the value for this flag is always the first parameter for this command.
‑RemoveDependencies (Optional) Specifies that unused dependencies of the package are also uninstalled.
‑Force (Optional) Forces the package to uninstall even if another package depends on it.
‑Version versionNumber (Optional) Specifies the version of the package to uninstall. The default is the latest version.
‑Project projectName (Optional) Specifies the project to uninstall the package from. This applies only to project packages. If a project is specified in the Default project list of the Package Manager Console window, this option is not required.

Sample Usage

The following example shows how to remove the elmah package. The two commands are equivalent; the second command explicitly includes the Id argument.

PM> Uninstall-Package elmah
PM> Uninstall-Package ‑Id elmah

The following example shows how to remove the GuEditor package and any dependencies only if no other packages are using those dependencies or are dependent on the package being removed. If GuEditor depends on Log4Net and elmah, but another installed package depends on Log4Net, this command will fail because it cannot remove Log4Net. (It is planned that in a future release the user will be prompted to resolve this conflict.)

PM> Uninstall-Package GuEditor -RemoveDependencies

The following example shows how to remove GuEditor the package even if other installed packages are dependent on it. (If you add ‑RemoveDependencies, any dependencies of GuEditor are also removed, even if other packages are dependent on them.)

PM> Uninstall-Package GuEditor -Force

Update-Package

Updates a package and its dependencies. If the new version of the package has new dependencies, the dependency packages are also installed. If the updated version no longer depends on a package and if no other packages depend on it, the dependency package is uninstalled.

Argument Description
‑Id packageName (Required) Specifies the package to update. Including the ‑Id flag is optional, because the value for this flag is always the first parameter for this command.
‑UpdateDependencies (Optional) Updates all of the package's dependencies to the latest version of each dependency.
‑Project projectName (Optional) Specifies the project to install the package into. This option applies only to project packages. If a project is specified in the Default project list of the Package Manager Console window, this option is not required. If no default project is selected, this option is required.
‑Source sourceURL (Optional) Specifies the URL of the package to install. The default is to look in the feed for the corresponding package URL.
‑Version versionNumber (Optional) Specifies the version that the package will be upgraded to. The default is the latest version.

Sample Usage

The following example shows how to update the elmah package to the latest version.

PM> Update-Package elmah

The following example shows how to update the elmah package from a specific package source.

PM> Update-Package elmah ‑Source http://packages.example.com/packages/elmah.nupack

The following example shows how to update the elmah package to a specific version.

PM> Update-Package elmah ‑Version 1.0.1

Get-Project

Returns a reference to the DTE (Development Tools Environment) for the active or specified project.

Argument Description
‑Name (Optional) Specifies the project to return. The default is the active project.
‑All (Optional) Returns every project in the solution.

Sample Usage

The following example shows how to get a reference to a project named MyClassLib1.

PM> Get‑Project MyClassLib1

Add‑BindingRedirect

Examines all assemblies in the output path for a project and adds binding redirects to the application configuration (app.config) file or to the web configuration (web.config) file where required.

Argument Description
‑Project (Optional) Specifies the project to analyze and add binding redirects to.
‑All (Optional) Specifies every project in the solution.

Sample Usage

The following example shows how to add binding redirects to a project named MyMvcApplication1.

PM> Add‑BindingRedirects MyMvcApplication1

Open-PackagePage

Opens a browser displaying the project website specified in the packageUrl field of the package's manifest.

Argument Description
‑Whatif (Optional) Prints out just the URL for the project page, without actually opening it.

Sample Usage

The following opens a package page for a given package

PM> Open-PackagePage Elmah

Related Information

NuGet documentation

Last edited Mar 25, 2011 at 8:43 PM by Haacked, version 4

Comments

No comments yet.