Finding and Installing a NuGet Package 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 theManage NuGet Packages dialog box. For more information, see [Using the Manage NuGet Packages
dialog](Using-the Add-Library-Package-Reference-Dialog-Box).
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 clickPackage 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 ofNuGet official package source. For more information about
alternative feeds, seeHosting 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 inSolution Explorer
when you open the window.)
When you enter commands, you can override these defaults. In the Package Manager Console window, enterGet-Package -ListAvailale
at the prompt to see a list of all packages that are available in the selected 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).
For more options that you can specify with the Get-Package
command, enterGet-Help Get-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 commandInstall-Package elmah
as shown in the following example:
For more options that you can specify with the Install-Package
command, enterget-help Install-Package
or see
Package Manager Console Powershell Reference.
NuGet retrieves the package from the specified package source and installs it in the project that is selected in theDefault 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 projectapp.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, thepackages 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 commandScaffold
, complete with tab expansion.
Removing a Package
From the Tools menu, select Library Package Manager and then clickPackage Manager Console. If you do not already know the name of the package you want to remove, enterGet-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 theUninstall-Package elmah
command as shown in the following example:
For more options that you can specify with the uninstall-package
command, enterget-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 theReferences folder or the
bin folder. (You might have to build the project to see it removed from thebin folder.)
- Files in the solution folder. The folder for the package you removed is deleted from thepackages 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.
Updating a Package
From the Tools menu, select Library Package Manager and then clickPackage Manager Console. To check if there are newer versions available for any installed packages, enterGet-Package -updates
at the prompt.
To update a package, enter Update-Package
with the package ID. For example, enter the commandUpdate-Package jQuery
. For more options that you can use with the
Update-Package
command, enter get-help Update-Package
or see (../Reference/Package-manager-Console-Commands).
Setting up a NuGet Powershell Profile
Powershell supports the concept of profiles which allow you to have commonly used PS commands available to you wherever you use PowerShell.
NuGet supports a NuGet specific profile typically located at:
%UserProfile%\Documents\WindowsPowerShell\NuGet_profile.ps1
The easiest way to find the profile file is to type $profile
within the NuGet Package Manager Console. For example, this is what I see on my machine.
PM> $profile
C:\Users\philha\Documents\WindowsPowerShell\NuGet_profile.ps1
This file doesn't necessarily exist by default. You can run the following set of commands to create it.
PM> mkdir -force (split-path $profile)
PM> notepad $profile
The first command creates the WindowsPowershell directory if it doesn’t already exist. The second command attempts to open the profile file in Notepad. If it doesn’t already exist, it prompts you to create the file. Within the profile file, you
can change PowerShell settings or add new commands you might find useful.
Here is a simple example of adding a command that allows you to set the font.
function Set-FontSize {
param(
[ValidateRange(6, 128)]
[Parameter(position=0, mandatory=$true)]
[int]$Size
)
$dte.Properties("FontsAndColors", "TextEditor").Item("FontSize").Value = $Size
}
Save the profile file and then restart Visual Studio. The next time you open the Package Manager Console, you will be able to make use of theSet-Font
command.
PM> Set-Font 24
That makes for much more readable code!
分享到:
相关推荐
Using the Android Support Package 258 Adding Fragment Support to Legacy Applications 259 Using Fragments in New Applications Targeting Older Platforms 259 Linking the Android Support Package to Your...
Helps you get the most out of core modules that provide advanced functionality, including the Polls Module, the Banner Manager, the Media Manager, Galleries, Weblinks, Content Syndication, and ...
3.4 Installing or Removing a Software Package with the pkgadd or pkgrm Command 50 3.5 Using Package Commands to Manage Software Packages 51 3.5.1 How to Install Packages with the pkgadd Command 51 ...
Written by a MySQL Community Manager for Oracle, MySQL and JSON: A Practical Programming Guide shows how to quickly get started using JSON with MySQL and clearly explains the latest tools and ...
A Recommender System for Finding Passengers and Vacant Taxis
本文介绍了newman算法的社团划分问题,有凝聚,和分层聚类的思想
Gaussian densities, and 2) finding the parameters of a hidden Markov model (HMM) (i.e., the Baum-Welch algorithm) for both discrete and Gaussian mixture observation models. We derive the update ...
Finding files and folders using the Site Search feature. The Import/Export FTP Sites Wizard that guides you through the steps to add sites to your Site Manager from simple text listings or from site ...
Using Sensors and the Sensor Manager Monitoring a Device's Movement and Orientation Introducing the Environmental Sensors Chapter 13: Maps, Geocoding, and Location-Based Services Using Location-Based ...
The Network Manager 358 Other Freedesktop Projects 360 Summary 360 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xv xvi Contents Chapter 13: Graphics and Audio 361 Linux and Graphics 361 X Windows 362 Open ...
Finding Maximum Contiguous Subsequence Sum using divide-and-conquer approach
XNA 4.0 Game Development...Run, jump, and squash enemies in a side-scrolling platform using the maps from your editor Modify your creations for the Xbox 360 platform and deploy your games to the console
Manually using the ESP and EBP registers 123 Optimizing Memory Access 123 Summary 124 Chapter 6: Controlling Execution Flow 127 The Instruction Pointer 127 Unconditional Branches 129 Jumps 129 Calls ...
A gain matrix calculated using both the Jacobian matrix and residual vector replaces the simple diagonal matrix of the LM solution, which results in a better estimation of the descent direction and ...
Finding the area and volume of a circle on matlab
It details the creation of four games, all in different styles, from start to finish using the Microsoft XNA Framework, including a puzzler, space shooter, multi-axis shoot-’em-up, and a jump-and-...
Using the Palette to Create a Window 227 Putting Widgets into the Window 228 Glade Creates an XML Representation of the GUI 230 Try It Out: Building a GUI from a Glade File 231 Creating a Real ...
Tutorial #1 - Installing the Tools Android and Projects Tutorial #2 - Creating a Stub Project Getting Around Android Studio Contents of Android Projects Introducing Gradle and the Manifest Tutorial #3...