Skip to content

Commit edc489a

Browse files
authored
Fixing dotnet SDK version parsing in build.psm1 (PowerShell#17198)
1 parent 5d7b8b9 commit edc489a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

build.psm1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,19 @@ function Start-PSBootstrap {
21962196

21972197
function Get-LatestInstalledSDK {
21982198
Start-NativeExecution -sb {
2199-
dotnet --list-sdks | Select-String -Pattern '\d*.\d*.\d*(-\w*\.\d*.\d*.\d*)?' | ForEach-Object { [System.Management.Automation.SemanticVersion]::new($_.matches.value) } | Sort-Object -Descending | Select-Object -First 1
2199+
dotnet --list-sdks | ForEach-Object {
2200+
# this splits strings like
2201+
# '6.0.202 [C:\Program Files\dotnet\sdk]'
2202+
# '7.0.100-preview.2.22153.17 [C:\Users\johndoe\AppData\Local\Microsoft\dotnet\sdk]'
2203+
# into version and path parts.
2204+
$version, $null = $_ -split '\s',2
2205+
try {
2206+
[System.Management.Automation.SemanticVersion]::new($version)
2207+
}
2208+
catch {
2209+
Write-Warning -Message "Unable to parse dotnet version semantically: $version"
2210+
}
2211+
} | Sort-Object -Descending | Select-Object -First 1
22002212
} -IgnoreExitcode 2> $null
22012213
}
22022214

0 commit comments

Comments
 (0)