Created
September 28, 2022 06:32
-
-
Save kapsiR/e7064babbef8dc4ac84a627717d54e5a to your computer and use it in GitHub Desktop.
Update all dotnet global tools at once
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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