Skip to content

Instantly share code, notes, and snippets.

@kapsiR
Created September 28, 2022 06:32
Show Gist options
  • Save kapsiR/e7064babbef8dc4ac84a627717d54e5a to your computer and use it in GitHub Desktop.
Save kapsiR/e7064babbef8dc4ac84a627717d54e5a to your computer and use it in GitHub Desktop.
Update all dotnet global tools at once
function Update-DotNet-Global-Tools
{
foreach ($toolInfoRow in $(dotnet tool list -g | Select-Object -Skip 2))
{
$toolInfo = $toolInfoRow.Split(" ", [StringSplitOptions]::RemoveEmptyEntries)
$toolName = $toolInfo[0]
$toolVersion = $toolInfo[1].Trim()
# Fetch version from NuGet
$nugetInfo = (dotnet tool search --take 1 $toolName | Select-Object -Skip 2)
$nugetVersion = $nugetInfo.Split(" ", [StringSplitOptions]::RemoveEmptyEntries)[1].Trim()
if ($nugetVersion -ne $toolVersion)
{
Write-Host "dotnet tool update -g $toolName"
dotnet tool update -g $toolName
}
else
{
Write-Host "Skip $toolName (no updates available)"
}
}
}
Update-DotNet-Global-Tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment