Nuget Update-Package With a Filter

- - posted in nuget, powershell | Comments

One of my biggest annoyances about nuget and powershell in general is the lack of universal support for unix like features such as pipe and grep. Lets say you have a solution with multiple projects in and you want to update to the latest versions of your internal dependencies, you’d proabably do something like.

1
2
3
Update-Package CompanyFoo.Package1
Update-Package CompanyFoo.Package2
Update-Package CompanyFoo.Package3

In the gems world you could do something like

1
gem update `gem list | grep CompanyFoo | cut -d ' ' -f 1`

What I’d like to be able to do is something like

1
Update-Package -like CompanyFoo

Or even

1
Update-Package | List-Package -like CompanyFoo

Sadly the closest I got was going though each packages.config file and filtering down the list

1
2
3
4
5
6
7
8
9
Get-ChildItem -path '.' -Recurse -Include 'packages.config' |
 Select-Xml -xpath '//package/@id' |
 Select-Object -ExpandProperty Node |
 Select-Object -ExpandProperty value |
 Sort-Object -Unique |
 Where-Object {$_ -like 'CompanyPackages*'} |
 ForEach-Object { Update-Package $_ }
     
 

Update

I take it all back, @neilbarnwell pointed out this lovely one liner

1
get-project -all | get-package | ?{ $_.Id -like 'Stripe*'} | Update-Package

Comments