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
STEP 3 Open the Package manager console
and run:
Update-Package -Reinstall -ProjectName MyProjB
That’s it! Three steps, a truly beautiful waltz. Hope it helps.
Cheers,
//Daniel
PS! If you want something for your builds: NuGet restore – PowerShell vs Rake