Skip to content

Instantly share code, notes, and snippets.

@jonnekleijer
Created November 28, 2023 23:27
Show Gist options
  • Select an option

  • Save jonnekleijer/24a90ac4fc28246aa7406d52f12a5599 to your computer and use it in GitHub Desktop.

Select an option

Save jonnekleijer/24a90ac4fc28246aa7406d52f12a5599 to your computer and use it in GitHub Desktop.
Update all csproj package references
$regex = 'PackageReference Include="([^"]*)" Version="([^"]*)"'
ForEach ($file in get-childitem . -recurse | Where-Object { $_.extension -like "*proj" }) {
$packages = Get-Content $file.FullName |
select-string -pattern $regex -AllMatches |
ForEach-Object { $_.Matches } |
ForEach-Object { $_.Groups[1].Value.ToString() } |
Sort-Object -Unique
ForEach ($package in $packages) {
write-host "Update $file package :$package" -foreground 'magenta'
$fullName = $file.FullName
Invoke-Expression "dotnet add $fullName package $package"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment