4

I am using Nuget via Visual Studio's Package Manager Console. For every project I need to add few packages e.g. xunit.contribs, fluentassertions and nsubstitute. To do that I type 3 commands in consolle.

I understand that console is just another powershell host and there should be a way to create a script (kind of Add-Test-Stuff.ps1) that will add several packages at once. What is the best way to do that?

3 Answers 3

10

I typically define my packages in arrays and execute them using a foreach loop

$angular = "AngularJS.Animate", "AngularJS.Core", "AngularJS.Locale", "AngularJS.Resource", "AngularJS.Route", "AngularJS.Sanitize", "AngularJS.Touch"
$angular | foreach {Install-Package $_} 

This can also be written as a one-liner

"AngularJS.Animate", "AngularJS.Core", "AngularJS.Locale", "AngularJS.Resource", "AngularJS.Route", "AngularJS.Sanitize", "AngularJS.Touch" | foreach {Install-Package $_} 
1

It is not direct answer to you question, sorry. But I've seen very nice practive adopted for Code52 IdeaStrike project.

They do not have any packages included in source control, instead they will be installed during first build of solution and downloaded automatically, depending on packages.config

The details of configuration are here:

Using NuGet without committing packages to source control

1
  • Yes, but you'll need to add them to packages.config somehow. I am wondering ho to do that in the fastest way :)
    – the_joric
    Jan 26, 2012 at 14:39
1

Put any script to your solution directory and you will be able to execute it from Package Manager Console.

3
  • OK, is it possible to put script to some home folder?
    – the_joric
    Jan 26, 2012 at 11:21
  • You can put it anywere in PATH. But I think this script is project specific. Not sure why to keep it somewhere else. Jan 26, 2012 at 14:57
  • 1
    well, I want to add the same set of packages to all my test projects
    – the_joric
    Jan 27, 2012 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.