How to install a NuGet package on the command line to a Visual Studio project

The NuGet Command Line does not actually install any packages. The install command is actually doing a restore operation.

This means that nuget.exe install will only download and extract the package into the output location. It will not modify the project file (so no references are added, no content files injected, no transformations applied, no MSBuild files imported), and it will also not run any PowerShell scripts.

I do believe that a similar request to yours is being tracked by the NuGet team, but feel free to log an issue there: http://nuget.codeplex.com.

To answer your question: the NuGet Command Line does not support your scenario at this moment (nuget.exe v2.8).


Well, it's not command line per se, but you can do this through the Package Manager Console in Visual Studio (accessed via Tools > Library Package Manager > Package Manager Console). When installing a package to multiple projects, the Package Manager Console is still better than the "Manage NuGet Packages for Solution" dialog because you can paste a list of project names instead of selecting them one by one in the dialog.

Use a command such as this:

Get-Project MyProject1,MyProject2,MyProject3 | Install-Package MyPackage

Source: this answer.

If you are tempted to try to use this command from outside Visual Studio, read these questions:

  • Use NuGet powershell commandlets from outside Visual Studio
  • Using NuGet Package Manager console outside Visual Studio to run Entity Framework Migrations

Tags:

Nuget