Install multiple packages through Nuget with a single command

I am using Nuget through the Visual Studio Package Manager console. For each project I need to add several packages, for example. xunit.contribs, fluentassertions and nsubstitute. To do this, I enter 3 commands in the console.

I understand that the console is another powershell node, and there must be a way to create a script (like Add-Test-Stuff.ps1) that will add several packages at once. What is the best way to do this?

+2
source share
3 answers

I usually 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 $_} 

It can also be written as single line

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

This is not a direct answer to your question, sorry. But I saw a very good practice adopted for the Code52 IdeaStrike project.

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

Configuration details are here:

Using NuGet Without Transferring Packages To Source

+1
source

Put any script in your solution directory and you can execute it from the package manager console.

+1
source

Source: https://habr.com/ru/post/927923/


All Articles