Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing multiple packages via Nuget by single command

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?

like image 973
the_joric Avatar asked Dec 17 '22 04:12

the_joric


1 Answers

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 $_} 
like image 58
Eric Herlitz Avatar answered Dec 18 '22 17:12

Eric Herlitz