notes from a passionate developer

Developer that lives by the mantra "code is meant to be shared".




This is a personal blog. The opinions expressed here represent my own and not those of my employer, nor current or previous. All content is published "as is", without warranty of any kind and I don't take any responsibility and can't be liable for any claims, damages or other liabilities that might be caused by the content.

Copy NuGets between projects in Visual Studio in seconds

Daniel WertheimDaniel Wertheim

Found my self putting up projects that were duplicates of other projects when it came to the NuGets that should be installed in the projects. There were no template and no “master” NuGet to install so every one needed to be added manually. But there’s of course a simpler way that takes seconds (if you deduct the time for downloading missing NuGets). Let me show you.

But wait a bit Mr. Isn’t this built in already with the magical NuGet download missing packages on build? Well glad you asked. I have Visual Studio Pro 2013 with the latest updates to NuGet package manger. I have enabled this setting under the package manager settings. What happens is that it downloads the packages, but it DOES NOT ADD THEM AS REFERENCES. At least not for me. But what if I enable the other magical thingie that messes with my project file to restore NuGets? Well, again, glad you asked. I don’t use that. Period! Neither should you: The right way to restore NuGet packages BUT IF ENABLED it still doesn’t work for me. So until it really works…

The Solution

Lets say we have an existing project MyProjA that has a bunch of NuGets that also should be installed in a new project MyProjB. Then you can fix this by:

STEP 1 Create MyProjB

STEP 2 In the Solution explorer, copy packages.config from MyProjA to MyProjB

Copy-NuGets between- projects-01

STEP 3 Open the Package manager console and run:

Update-Package -Reinstall -ProjectName MyProjB  

Copy-NuGets between- projects-02

Copy-NuGets between- projects-03

That’s it! Three steps, a truly beautiful waltz. Hope it helps.



PS! If you want something for your builds: NuGet restore – PowerShell vs Rake

Developer that lives by the mantra "code is meant to be shared".