Package Manager Console in Visual Studio

Introduction

The Package Manager Console is a PowerShell console within Visual Studio used to interact with NuGet and automate Visual Studio. You can access the Package Manager Console from within Visual Studio by going to Tools -> Library Package Manager -> Package Manager Console.

library package manager

The following is a screen shot for the console:

package manager console

Benefits of using Package Manager Console (PMC)

So, why should you bother to use PMC given that you have a nice UI for the NuGet system integrated in Visual Studio? The following are the benefits of using PMC over the NuGet UI:

  • Using PMC, you can automate the addition of packages into your solution instead of each team member going to the NuGet UI to add packages.
     
  • The PMC scripts can be part of the Visual Studio solution itself so that any new team member can simply run those scripts when setting up the solution.
     
  • NuGet will always install the latest version of a package however, using PMC you can specify the version number of the package to install.
     
  • PMC is useful if you wish to manage the dependencies manually without using NuGet, for example to install a package without dependencies use the flag -IgnoreDependencies.
     
  • PMC can also be useful to reinstall a package using the -reinstall flag. This provides a kind of repair functionality.
     
  • The PMC scripts can also be part of the continuous integration system.
     
  • PMC is not just an alternative to NuGet. Many packages add commands to PMC for additional functionality. For example: EntityFramework adds a host of commands to manage code first migrations.
Let's see some quick examples of the usage. Now, you can go ahead and type a command to install a new package in your project:

package manager pm

To get help on any command, you can type the command Get-help <command>.

install packages

You can press the Tab key after entering a few characters to trigger the autocomplete functionality. You can even resolve the package names using the Tab key when using the install-package command.

database update

You can change the default project from the top right drop down. The commands will be applied to the selected project only.

 test package manager


Similar Articles