Managing Packages Using the Package Manager Console


This topic describes how to find, install, remove, and update NuGet packages using PowerShell commands. You can also work with packages using the Manage NuGet Packages dialog box. For more information, see Manage NuGet Packages Using the Package Manager dialog.

Using PowerShell commands is required if you want to install a package without having a solution open. It‘s also required in some cases for packages that create commands that you can access only by using PowerShell.

Finding a Package

From the Tools menu, select Library Package Manager and then click Package Manager Console.

The Package Manager Console window is displayed.

The two drop-down lists set default values that let you omit parameters from the commands you enter in the window:

  • In the Package source list, select the default source (NuGet package feed) that you want your commands to use. Typically you will leave this as its default value of NuGet official package source. For more information about alternative feeds, see Hosting Your Own NuGet Feeds.
  • In the Default project list, select the default project that you want your commands to work with. (The default value will be the first project in the solution, not necessarily the one you have selected in Solution Explorer when you open the window.)

When you enter commands, you can override these defaults. In the Package Manager Console window, enter Get-Package -ListAvailable at the prompt to see a list of all packages that are available in the selected package source. Starting NuGet 3.0 Beta or higher, Get-Package also takes a -PageSize switch, which enables paging support for listing available packages from a package source.

For the default package source, that command is going to list thousands of packages. It makes better sense to specify a filter.

For example, to find the logging package ELMAH, enter Get-Package -ListAvailable -Filter elmah (the name of the package) orGet-Package -Filter Logging -ListAvailable (a keyword in the package description). Starting NuGet client 3.0 Beta or higher, these Get-Package commands can be replaced by Find-Package elmah or Find-Package Logging.

For more options that you can specify with the Get-Package and Find-Package command, enter Get-Help Get-Package and Get-Help Find-Package, or see Package Manager Console Powershell Reference.

Installing a Package

After you have found a package that you want to install, use the Install-Package command with the name of the package. For example, enter the command Install-Package elmah as shown in the following example:

Refer here for a complete list of PowerShell Reference on Install

NuGet retrieves the package from the specified package source and installs it in the project that is selected in the Default project drop-down list (unless you specify a different project in the command). Files are copied to the solution, references might be added to the project, the project app.config or web.config file might be updated, etc.

If the package you are installing is dependent on other packages, NuGet installs them also if they are not already installed.

If the package requires license acceptance, you will not be prompted in a dialog box. Instead, a message states that your use of the library constitutes license acceptance.

In Solution Explorer, you can see references that Visual Studio has added for the installed library or libraries.

If your app.config or web.config file required changes, those have been applied. The following example shows some of the changes for ELMAH.

A new folder named packages is created in your solution folder. (If your project does not have a solution folder, the packages folder is created in the project folder.)

The packages folder contains a subfolder for each installed package. This subfolder contains the files installed by the package. It also contains the package file itself (the .nupkg file, which is a .zip file that contains all of the files included in the package).

You can now use the library in your project. IntelliSense works when you enter code, and library features such as the ELMAH logging information page work when you run the project.

Extending The Package Manager Console With Packages

Some packages install new commands that you can use in the Package Manager Console window. One example of such a package isMvcScaffolding, which creates commands you can use to generate ASP.NET MVC controllers and views. The following illustration shows that installing MvcScaffolding creates a new command Scaffold, complete with tab expansion.

Removing a Package

From the Tools menu, select Library Package Manager and then click Package Manager Console. If you do not already know the name of the package you want to remove, enter Get-Package at the prompt without any flags to see a list of all of the packages that are currently installed.

To remove a package, use the Uninstall-Package command with the name of the package. For example, use the Uninstall-Package elmah command as shown in the following example:

For more options that you can specify with the uninstall-package command, enter get-help uninstall-package or see Package Manager Console Powershell Reference.

The following package elements are removed:

  • References in the project. In Solution Explorer, you no longer see the library in the References folder or the bin folder. (You might have to build the project to see it removed from the bin folder.)
  • Files in the solution folder. The folder for the package you removed is deleted from the packages folder. If it is the only package you had installed, the packages folder is also deleted.)
  • Any changes that were made to your app.config or web.config file are undone.

If other packages were installed because they were dependencies of the package that you removed, and if no other packages remain that are dependent on the dependency packages, the dependency packages are also removed.

Refer here for a complete list of PowerShell Reference on Uninstall

Updating a Package

From the Tools menu, select Library Package Manager and then click Package Manager Console. To check if there are newer versions available for any installed packages, enter Get-Package -updates at the prompt.

To update a package, enter Update-Package with the package ID. For example, enter the command Update-Package jQuery. For more options that you can use with the Update-Package command, enter get-help Update-Package or see here.

Refer here for a complete list of PowerShell Reference on Update

Setting up a NuGet Powershell Profile

For customizing your PowerShell console, click here

时间: 07-05

Managing Packages Using the Package Manager Console的相关文章

Visual Studio 2015 新建MVC项目 Package Manager Console不能使用 (HRESULT: 0x80131500)

Visual studio 2015 突然新建不了MVC项目,报出错误: HRESULT: 0x80131500 在折腾了很长时间,最后在Github上看到这样一个贴 地址: 点击下载地址: 下载安装(安装很慢,可能需要重启之后再安装) 安装完成之后,Vs问题修复了 Package Manager Console 也修复了 造成这个

salt package manager (SPM)

salt package manager 简称SPM,使用man查看spm命令的使用方法,这一部分内容比较多,初浅的看了下文档,暂时先总结个大概,后续慢慢在探究一下细节,再进行补充. salt 的包管理主要包含以下3个部分, 关系如图示: (1)Packaging System  包组织系统:主要内容包含如何建立一个SPM Packages. 解析formula格式的目录结构: (2)Repo System  建立repo包仓库和相关信息    (3)Salt Master  如何安装.spm的

你需要知道的包管理器(Package Manager)

最近我花了一点时间关注了在不同系统之中所用到的包管理器(Package Manager) .最开始的时候,我是在使用Linux操作系统时,对这种工具以及它背后的想法深深迷恋住了:这真是自由的软件世界.全世界所有的开发人员都可以将自己觉得有用的组件或者软件发布到一个共用的地方,其他的所有人都可以很方便地按需取用. 让我们记住Richard Stallman 以及他提出并创立的GNU计划.   在Linux系统中,包管理器是如

RPM(RPM Package Manager)程序包管理工具的常见使用方法

软件包有两种: 二进制格式的软件包和源码程序包. 如何选择适合自己的二进制格式的软件包? 1.根据CPU架构选择软件包 二进制格式的软件包就是已经把源程序转化为CPU所支持的指令集,它可以直接运行的.因为不同架构的CPU指令集不完全一样的.所以二进制格式的 软件包通常会标识适用于那种架构的CPU. CPU 常见平台arch:     1).Power  造价高.性能强劲     2).简化板的 PowerPC     3).UItraSparc     4).x86 功耗低,性能接近服务器级架构

RPM(RedHat Package Manager)

RPM(RedHat Package Manager) RPM安装包管理器作为redhat开发的用于在互联网或者是cd上进行下载包安装和管理,非常好用的.在CentOS上来说,它通常生成以.rpm结尾的文件. 通常这些程序包由下列四部分组成 part1.一些二进制格式的程序(这是指编译完成的) 它们在CentOS5.6等环境下通常在/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin等目录下,还有一些第三方的二进制应用也安装在/

Linux - Managing Packages and Processes

Part 1: Package Management Package management is a system by which software can be installed, updated, queried or removed from a filesystem. In Linux, there are many different software package management systems, but the two most popular are those fr

RPM是RedHat Package Manager(RedHat软件包管理工具)

RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序” rpm 执行安装包二进制包(Binary)以及源代码包(Source)两种.二进制包可以直接安装在计算机中,而源代码包将会由RPM自动编译.安装.源代码包经常以src.rpm作为后缀名. 常用命令组合: -ivh:安装显示安装进度--install--verbose--hash -Uvh:升级软件包--Update: -ql:列出RPM软件包内的文件信息[Query Pa

Ubuntu An error occurred,please run Package Manager..

转自 An error occurred,please run Package Manager from the right-click menu or apt-get in a terminal to see what is wrong.The error message was: 'Error:BrokenCount>0'This usually means that your

NPM - Node Package Manager - Node 包管理器

NPM - Node Package Manager - Node 包管理器 NPM 是什么? npm(全称Node Package Manager,即node包管理器)是Node.js默认的.以JavaScript编写的软件包管理系统. npm 官方网站 npm 官方文档 一般当我们说npm的时候可能指3件事 NPM 网站: NPM 包管理库,存储了大量的JavaScript代码库 NPM 客户端,我们所使用的npm命令行工具.使用JavaScrip