diff --git a/scripts/common.lib.ps1 b/scripts/common.lib.ps1 index a83f19a7f6..1e363435f8 100644 --- a/scripts/common.lib.ps1 +++ b/scripts/common.lib.ps1 @@ -60,17 +60,11 @@ function Write-Log { [string] $Level = "Success" ) - - $currentColor = $Host.UI.RawUI.ForegroundColor - try { - $Host.UI.RawUI.ForegroundColor = if ("Success" -eq $Level) { "Green" } else { "Red" } - if ($message) - { - Write-Output "... $message" - } - } - finally { - $Host.UI.RawUI.ForegroundColor = $currentColor + + if ($message) + { + $color = if ("Success" -eq $Level) { "Green" } else { "Red" } + Write-Host "... $message" -ForegroundColor $color } } @@ -265,15 +259,20 @@ public class ProcessOutputter { AppendLine(e.Data); if (!suppressOutput) { - var fg = Console.ForegroundColor; - try - { - Console.ForegroundColor = _color; - Console.WriteLine(e.Data); - } - finally - { - Console.ForegroundColor = fg; + // These handlers can run at the same time, + // without lock they sometimes grab the color the other + // one set. + lock (Console.Out) { + var fg = Console.ForegroundColor; + try + { + Console.ForegroundColor = _color; + Console.WriteLine(e.Data); + } + finally + { + Console.ForegroundColor = fg; + } } } }; diff --git a/scripts/perf/perf.ps1 b/scripts/perf/perf.ps1 index 88c31e8cfa..348a738ef9 100644 --- a/scripts/perf/perf.ps1 +++ b/scripts/perf/perf.ps1 @@ -175,13 +175,10 @@ function Get-ConsoleRunnerPath($runner, $targetFrameWork) function Write-Log ([string] $message, $messageColor = "Green") { - $currentColor = $Host.UI.RawUI.ForegroundColor - $Host.UI.RawUI.ForegroundColor = $messageColor if ($message) { - Write-Output "... $message" + Write-Host "... $message" -ForegroundColor $messageColor } - $Host.UI.RawUI.ForegroundColor = $currentColor } function Get-ProductVersion($filePath) @@ -352,24 +349,27 @@ function Invoke-PerformanceTests # function Invoke-DisplayResults { - $currentColor = $Host.UI.RawUI.ForegroundColor - $Host.UI.RawUI.ForegroundColor = "Green" - $osDetails = Get-SystemInfo - "`n" - "Machine Configuration" - $osDetails | Format-List 'MachineName', 'OSName', 'OSVersion', 'MachineType' , 'Processor', 'LogicalCores', 'RAMSize' - - if($DefaultAction -eq "Both" -or $DefaultAction -eq "Discovery") - { - $Script:TPT_Results | Where-Object {$_.Action -like "Discovery"} | Format-Table 'Runner', 'Adapter', 'Action', 'ElapsedTime', 'Goal', 'Delta', 'Status', 'PayLoad', 'RunnerVersion', 'AdapterVersion' -AutoSize - } + try { + $currentColor = $Host.UI.RawUI.ForegroundColor + $Host.UI.RawUI.ForegroundColor = "Green" + $osDetails = Get-SystemInfo + "`n" + "Machine Configuration" + $osDetails | Format-List 'MachineName', 'OSName', 'OSVersion', 'MachineType' , 'Processor', 'LogicalCores', 'RAMSize' + + if($DefaultAction -eq "Both" -or $DefaultAction -eq "Discovery") + { + $Script:TPT_Results | Where-Object {$_.Action -like "Discovery"} | Format-Table 'Runner', 'Adapter', 'Action', 'ElapsedTime', 'Goal', 'Delta', 'Status', 'PayLoad', 'RunnerVersion', 'AdapterVersion' -AutoSize + } - if($DefaultAction -eq "Both" -or $DefaultAction -eq "Execution") - { - $Script:TPT_Results | Where-Object {$_.Action -like "Execution"} | Format-Table 'Runner', 'Adapter', 'Action', 'ElapsedTime', 'Goal', 'Delta', 'Status', 'PayLoad', 'RunnerVersion', 'AdapterVersion' -AutoSize + if($DefaultAction -eq "Both" -or $DefaultAction -eq "Execution") + { + $Script:TPT_Results | Where-Object {$_.Action -like "Execution"} | Format-Table 'Runner', 'Adapter', 'Action', 'ElapsedTime', 'Goal', 'Delta', 'Status', 'PayLoad', 'RunnerVersion', 'AdapterVersion' -AutoSize + } + } + finally { + $Host.UI.RawUI.ForegroundColor = $currentColor } - - $Host.UI.RawUI.ForegroundColor = $currentColor if($ExportResults -ne $null -and $ExportResults -eq "csv") { diff --git a/scripts/test.ps1 b/scripts/test.ps1 index ce05418dcf..d0022db77b 100644 --- a/scripts/test.ps1 +++ b/scripts/test.ps1 @@ -119,13 +119,10 @@ $Script:ScriptFailed = $false function Write-Log ([string] $message, $messageColor = "Green") { - $currentColor = $Host.UI.RawUI.ForegroundColor - $Host.UI.RawUI.ForegroundColor = $messageColor if ($message) { - Write-Output "... $message" + Write-Host "... $message" -ForegroundColor $messageColor } - $Host.UI.RawUI.ForegroundColor = $currentColor } function Write-VerboseLog([string] $message) diff --git a/scripts/verify-sign.ps1 b/scripts/verify-sign.ps1 index 136e5e6364..dff004b0b8 100644 --- a/scripts/verify-sign.ps1 +++ b/scripts/verify-sign.ps1 @@ -151,12 +151,6 @@ function Write-Debug ([string] $message) function Write-ToCI ([string] $message, [string]$type, [switch]$vso) { - $currentColor = $Host.UI.RawUI.ForegroundColor - - if($type -eq "error") { - $Host.UI.RawUI.ForegroundColor = "Red" - } - if ($message -or $vso -or $type) { $prefix = "" @@ -164,15 +158,15 @@ function Write-ToCI ([string] $message, [string]$type, [switch]$vso) $prefix = "vso" } - Write-Output "##$prefix[$type]$message" + $color = if($type -eq "error") { "Red" } else { $Host.UI.RawUI.ForegroundColor } + Write-Host "##$prefix[$type]$message" -ForegroundColor $color } - $Host.UI.RawUI.ForegroundColor = $currentColor } Write-Debug "Variables used: " Get-ChildItem variable:TPB_* -Write-Output "" -Write-Output "" +Write-Host "" +Write-Host "" Verify-Assemblies Verify-NugetPackages