From 5cdb68929c12d86ba9103329645c7bfad199b286 Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Thu, 30 Nov 2017 17:55:46 -0600 Subject: [PATCH 1/3] Fix Get-EnvironmentInformation IsCoreCLR logic --- build.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index 9c97a4e65ef..2be26b76beb 100644 --- a/build.psm1 +++ b/build.psm1 @@ -100,12 +100,12 @@ function Get-EnvironmentInformation # Use the .NET Core APIs to determine the current platform. # If a runtime exception is thrown, we are on Windows PowerShell, not PowerShell Core, # because System.Runtime.InteropServices.RuntimeInformation - # and System.Runtime.InteropServices.OSPlatform do not exist in Windows PowerShell. + # and System.Runtime.InteropServices.OSPlatform do not exist in .NET versions older than 4.7.1. try { $Runtime = [System.Runtime.InteropServices.RuntimeInformation] $OSPlatform = [System.Runtime.InteropServices.OSPlatform] - $environment += @{'IsCoreCLR' = $true} + $environment += @{'IsCoreCLR' = 'Core' -eq $PSVersionTable.PSEdition} $environment += @{'IsLinux' = $Runtime::IsOSPlatform($OSPlatform::Linux)} $environment += @{'IsMacOS' = $Runtime::IsOSPlatform($OSPlatform::OSX)} $environment += @{'IsWindows' = $Runtime::IsOSPlatform($OSPlatform::Windows)} From 163ef95936458f3cc198270f489033ed04641c23 Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Fri, 1 Dec 2017 11:49:04 -0600 Subject: [PATCH 2/3] Address PR Feedback --- build.psm1 | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/build.psm1 b/build.psm1 index 2be26b76beb..e6cdba5b874 100644 --- a/build.psm1 +++ b/build.psm1 @@ -97,19 +97,12 @@ function Get-PSCommitId function Get-EnvironmentInformation { $environment = @{} - # Use the .NET Core APIs to determine the current platform. - # If a runtime exception is thrown, we are on Windows PowerShell, not PowerShell Core, - # because System.Runtime.InteropServices.RuntimeInformation - # and System.Runtime.InteropServices.OSPlatform do not exist in .NET versions older than 4.7.1. - try { - $Runtime = [System.Runtime.InteropServices.RuntimeInformation] - $OSPlatform = [System.Runtime.InteropServices.OSPlatform] - - $environment += @{'IsCoreCLR' = 'Core' -eq $PSVersionTable.PSEdition} - $environment += @{'IsLinux' = $Runtime::IsOSPlatform($OSPlatform::Linux)} - $environment += @{'IsMacOS' = $Runtime::IsOSPlatform($OSPlatform::OSX)} - $environment += @{'IsWindows' = $Runtime::IsOSPlatform($OSPlatform::Windows)} - } catch { + if ($PSVersionTable.ContainsKey("PSEdition") -and "Core" -eq $PSVersionTable.PSEdition) { + $environment += @{'IsCoreCLR' = $true} + $environment += @{'IsLinux' = $IsLinux} + $environment += @{'IsMacOS' = $IsMacOS} + $environment += @{'IsWindows' = $IsWindows} + } else { $environment += @{'IsCoreCLR' = $false} $environment += @{'IsLinux' = $false} $environment += @{'IsMacOS' = $false} From 2b06637afa09d091d22ebcdb5ebd533aa8d3abcb Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Fri, 1 Dec 2017 14:35:07 -0600 Subject: [PATCH 3/3] Address PR Feedback --- build.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/build.psm1 b/build.psm1 index e6cdba5b874..a51eb6d47b5 100644 --- a/build.psm1 +++ b/build.psm1 @@ -97,6 +97,7 @@ function Get-PSCommitId function Get-EnvironmentInformation { $environment = @{} + # PowerShell Core will likely not be built on pre-1709 nanoserver if ($PSVersionTable.ContainsKey("PSEdition") -and "Core" -eq $PSVersionTable.PSEdition) { $environment += @{'IsCoreCLR' = $true} $environment += @{'IsLinux' = $IsLinux}