Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active September 9, 2023 14:14
Show Gist options
  • Save guitarrapc/77a3edc07001fd689f2253b3c8817d31 to your computer and use it in GitHub Desktop.
Save guitarrapc/77a3edc07001fd689f2253b3c8817d31 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Update all dotnet tools installed on the system.
See https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools for dotnet-tools.
.EXAMPLE
# Update Project's dotnet tools
Update-DotnetTools
# Update Global dotnet tools
Update-DotnetTools -Global
#>
function Update-DotnetTools {
param(
[Switch]$Global
)
$globalSwitch = ""
if ($Global) {
$globalSwitch = "-g"
}
# $ dotnet tool list -g
# Package Id Version Commands
# ---------------------------------------------------
# dotnet-ildasm 0.12.2 dotnet-ildasm
# unitybuildrunner 3.4.0 UnityBuildRunner
$tools = dotnet tool list $globalSwitch | Select-Object -Skip 2
# dotnet-ildasm 0.12.2 dotnet-ildasm
# unitybuildrunner 3.4.0 UnityBuildRunner
foreach ($tool in $tools) {
# dotnet-ildasm 0.12.2 dotnet-ildasm
# 13
$end = $tool.IndexOf(" ")
# dotnet-ildasm
$toolName = ($tool.Substring(0, $end)).Trim()
dotnet tool update $globalSwitch "$toolName"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment