简体   繁体   中英

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

I downloaded nuget.exe and I have tried the install. I would like to target a Visual Studio project so it adds a reference on the command line outside of Visual Studio. It is simply downloading the package with a version number on the end. MyOutputDirectory is the output directory which has a Visual studio solution there.

nuget install nhibernate -o MyOutputDirectory

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM