@@ -208,7 +208,7 @@ function Start-ScriptAnalyzerBuild
208
208
if ( -not $script :DotnetExe ) {
209
209
$script :DotnetExe = Get-DotnetExe
210
210
}
211
- $buildOutput = & $script :DotnetExe build -- framework $framework -- configuration " $config "
211
+ $buildOutput = & $script :DotnetExe build -- framework $framework -- configuration " $config " 2>&1
212
212
if ( $LASTEXITCODE -ne 0 ) { throw " $buildOutput " }
213
213
}
214
214
catch {
@@ -368,8 +368,11 @@ function ConvertTo-PortableVersion {
368
368
$h [' PrereleaseLabel' ] = [String ]::Empty
369
369
}
370
370
$customObject = [pscustomobject ]$h
371
+ # we do this so we can get an approximate sort, since this implements a pseudo-version
372
+ # type in script, we need a way to find the highest version of dotnet, it's not a great solution
373
+ # but it will work in most cases.
371
374
Add-Member - inputobject $customObject - Type ScriptMethod - Name ToString - Force - Value {
372
- $str = " {0}.{1}.{2}" -f $this.Major , $this.Minor , $this.Patch
375
+ $str = " {0:0000 }.{1:0000 }.{2:0000}.{3:0000 }" -f $this.Major , $this.Minor , $this.Patch
373
376
if ( $this.PrereleaseLabel ) {
374
377
$str += " -{0}" -f $this.PrereleaseLabel
375
378
}
@@ -445,15 +448,15 @@ function Get-InstalledCLIVersion {
445
448
$sdkList = & $script :DotnetExe -- list- sdks 2>&1
446
449
$sdkList = " Unknown option"
447
450
if ( $sdkList -match " Unknown option" ) {
448
- $installedVersions = & $script :DotnetExe -- version
451
+ $installedVersions = & $script :DotnetExe -- version 2> $null
449
452
}
450
453
else {
451
454
$installedVersions = $sdkList | Foreach-Object { $_.Split ()[0 ] }
452
455
}
453
456
}
454
457
catch {
455
458
Write-Verbose - Verbose " $_ "
456
- $installedVersions = & $script :DotnetExe -- version
459
+ $installedVersions = & $script :DotnetExe -- version 2> $null
457
460
}
458
461
return (ConvertTo-PortableVersion $installedVersions )
459
462
}
@@ -505,8 +508,8 @@ function Get-DotnetExe
505
508
# the problem is that invoking dotnet on a version which is lower than the specified
506
509
# version in global.json will produce an error, so we can only take the dotnet which executes
507
510
$latestDotnet = $discoveredDotNet |
508
- Where-Object { try { & $_ -- version } catch { } } |
509
- Sort-Object { [ version ] (& $_ -- version) } |
511
+ Where-Object { try { & $_ -- version 2> $null } catch { } } |
512
+ Sort-Object { $pv = ConvertTo-PortableVersion (& $_ -- version 2> $null ); " $pv " } |
510
513
Select-Object - Last 1
511
514
if ( $latestDotnet ) {
512
515
Write-Verbose - Verbose " Found dotnet here: $latestDotnet "
0 commit comments