From 737112831a5b4d3dccbf80b7aea6549adb92bc4e Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Sat, 2 Dec 2017 05:39:04 -0600 Subject: [PATCH] Fix Get-EnvironmentInformation IsCoreCLR logic (#5592) * Fix Get-EnvironmentInformation IsCoreCLR logic Replace $Runtime = [System.Runtime.InteropServices.RuntimeInformation] and $OSPlatform = [System.Runtime.InteropServices.OSPlatform] with ($PSVersionTable.ContainsKey("PSEdition") -and $PSVersionTable.PSEdition -eq "Core"). --- build.psm1 | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/build.psm1 b/build.psm1 index 9c97a4e65..a51eb6d47 100644 --- a/build.psm1 +++ b/build.psm1 @@ -97,19 +97,13 @@ 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 Windows PowerShell. - try { - $Runtime = [System.Runtime.InteropServices.RuntimeInformation] - $OSPlatform = [System.Runtime.InteropServices.OSPlatform] - + # 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' = $Runtime::IsOSPlatform($OSPlatform::Linux)} - $environment += @{'IsMacOS' = $Runtime::IsOSPlatform($OSPlatform::OSX)} - $environment += @{'IsWindows' = $Runtime::IsOSPlatform($OSPlatform::Windows)} - } catch { + $environment += @{'IsLinux' = $IsLinux} + $environment += @{'IsMacOS' = $IsMacOS} + $environment += @{'IsWindows' = $IsWindows} + } else { $environment += @{'IsCoreCLR' = $false} $environment += @{'IsLinux' = $false} $environment += @{'IsMacOS' = $false}