Skip to content

Commit a3e81e1

Browse files
committed
Attempt to quieten build output.
Throw away stderr of dotnet execution under some case and emit it in others. Change ToString of PortableVersion to enable better sorts
1 parent c19ae0a commit a3e81e1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

build.psm1

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function Start-ScriptAnalyzerBuild
208208
if ( -not $script:DotnetExe ) {
209209
$script:DotnetExe = Get-DotnetExe
210210
}
211-
$buildOutput = & $script:DotnetExe build --framework $framework --configuration "$config"
211+
$buildOutput = & $script:DotnetExe build --framework $framework --configuration "$config" 2>&1
212212
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
213213
}
214214
catch {
@@ -368,8 +368,11 @@ function ConvertTo-PortableVersion {
368368
$h['PrereleaseLabel'] = [String]::Empty
369369
}
370370
$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.
371374
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
373376
if ( $this.PrereleaseLabel ) {
374377
$str += "-{0}" -f $this.PrereleaseLabel
375378
}
@@ -445,15 +448,15 @@ function Get-InstalledCLIVersion {
445448
$sdkList = & $script:DotnetExe --list-sdks 2>&1
446449
$sdkList = "Unknown option"
447450
if ( $sdkList -match "Unknown option" ) {
448-
$installedVersions = & $script:DotnetExe --version
451+
$installedVersions = & $script:DotnetExe --version 2>$null
449452
}
450453
else {
451454
$installedVersions = $sdkList | Foreach-Object { $_.Split()[0] }
452455
}
453456
}
454457
catch {
455458
Write-Verbose -Verbose "$_"
456-
$installedVersions = & $script:DotnetExe --version
459+
$installedVersions = & $script:DotnetExe --version 2>$null
457460
}
458461
return (ConvertTo-PortableVersion $installedVersions)
459462
}
@@ -505,8 +508,8 @@ function Get-DotnetExe
505508
# the problem is that invoking dotnet on a version which is lower than the specified
506509
# version in global.json will produce an error, so we can only take the dotnet which executes
507510
$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" } |
510513
Select-Object -Last 1
511514
if ( $latestDotnet ) {
512515
Write-Verbose -Verbose "Found dotnet here: $latestDotnet"

0 commit comments

Comments
 (0)