So the scenario is this…
I’ve created a solution, added my projects, added some NuGet packages and all’s good with the world. Then I need to add a new project and reference some NuGet packages which I’m already using.
What’s the best way to do this?
In the past I’d go to the “Manage NuGet Packages” on the references section of a project and add the package again. However here’s the problem with this solution – unless you specify a specific version (you’ll be doing this through the Package Manager Console), you may find a different version of a package installed into your solution, which has its obvious downsides.
What about referencing the assemblies you require directly, i.e. use Add Reference and browse for them? I don’t actually know (at this time) whether this causes problems for NuGet with updates etc. but it’s not a great way when a package requires multiple assemblies, which make up a package.
What we really want is a way to say, reuse this package (already downloads and installed in the solution file system) in my new project.
The solution is simple, but I never noticed it before (how embarrassing)
One of the projects I’m working on has NuGet packages hosted in-house and they change often (hey its continuous deployment, that’s cool). So when I create a new project, all I want to do is get NuGet to somehow reference my existing package(s) and have NuGet handle all the references etc.
Well it’s actually all there, built into NuGet/Visual Studio.
- Select the solution in solution explorer
- Right mouse click and select Manage NuGet Packages for solution…
- Select Installed packages
- Locate the package that’s already installed
- Click the Manager button
- Now simply locate your new project and tick the checkbox next
- Click OK, sit back and relax