Installing multiple nuget packages in one command
One of my problems with nuget is that I can’t install multiple packages in one command while we can do the same in other package managers…
This is a cross-post of my Medium post.
One of my problems with nuget is that I can’t install multiple packages in one command while we can do the same in other package managers like npm or gem or even choco (while choco is basically using the same infrastructure as nuget). So I tried to do so with a little help from powershell:
I created Profile.ps1
file in Documents\WindowsPowerShell
and add this code to the file:
then in your Package Manager Console, you can write nugetip package0 package1 package2 ...
How this works?
Nuget uses a powershell session under the hood. Powershell has profile files, files like ~/.bashrc
and bash_profile
in distros using bash. Whenever a new session starts, powershell runs Profile.ps1
from a couple locations (you can have different files for different profiles). Here we use profile of current user in current host console profile.
Here, we add a function to our powershell session for installing multiple packages in one line command and use [Parameter(ValueFromRemainingArguments=$true)[string[]]$packages
to ask powershell to fill $packages
array with any unasked parameters. So all of the inputs will be stores in $packages
array. Now for each input, we install the package.
Future Works
I didn’t need to install specific version of a package yet. But if I do, I can modify command structure to nugetip package0:version package1 package2:version ...
and transfer it to install-package
extracting package name and version using-match