Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to add NuGet packages as project references in VS2012?

Ok. Really quick question, I'm probably just being thick.

If you right-click on a projects 'references' folder then 'Manage NuGet Packages' you can then install packages and they are automatically referenced by the project you clicked on. But then I want to add the same reference to other projects in the same solution. If you repeat previous but click on another project the only option is to uninstall the package (since it's already installed), what is the proper way to add an existing (already installed) NuGet package as a project reference? Am I to add the reference using the normal dialog and 'browse' to the dll in the packages folder? Use one method to add the first reference then another for subsequent references? That doesn't seem right.

like image 496
Dr. Ogden Wernstrom Avatar asked Feb 21 '13 11:02

Dr. Ogden Wernstrom


People also ask

How do I add a reference to a project in Visual Studio?

You can also right-click the project node and select Add > Project Reference. If you see a References node in Solution Explorer, you can use the right-click context menu to choose Add Reference. Or, right-click the project node and select Add > Reference.


2 Answers

You can use Manage NuGet packages for Solution... by:

  • right-clicking on solution
  • Tools > Library Package Manager > Manage NuGet packages for Solution

Then you can choose in which projects install package as on screenshot below: enter image description here Additionally you can add installed package to another projects in solution using the same Manage NuGet packages for Solution.... enter image description here

like image 184
Pavel Bakshy Avatar answered Oct 06 '22 01:10

Pavel Bakshy


The other answer here didn't help me. Here's what I did, I don't know any other way to do it. I'm using VS 2013.

  • I installed the package in the Package Manager Console, e.g. PM> Install-Package Newtonsoft.Json
  • In the Solution Explorer, right click references, select Add Reference
  • Click Browse, and navigate to the dll in the packages directory under the folder of the solution.

This adds a relative path for the reference to the project, so it should work with other people getting the code from source control into different directories.

like image 32
kristianp Avatar answered Oct 06 '22 00:10

kristianp