Skip to content

Get-EnvironmentInformation does not properly check for CoreCLR #5581

Closed

Description

The following code incorrectly reports that I am using CoreCLR on Windows PowerShell 5.1

PowerShell/build.psm1

Lines 100 to 117 in 7dce411

# 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]
$environment += @{'IsCoreCLR' = $true}
$environment += @{'IsLinux' = $Runtime::IsOSPlatform($OSPlatform::Linux)}
$environment += @{'IsMacOS' = $Runtime::IsOSPlatform($OSPlatform::OSX)}
$environment += @{'IsWindows' = $Runtime::IsOSPlatform($OSPlatform::Windows)}
} catch {
$environment += @{'IsCoreCLR' = $false}
$environment += @{'IsLinux' = $false}
$environment += @{'IsMacOS' = $false}
$environment += @{'IsWindows' = $true}
}

Steps to reproduce

Import-Module .\build.psm1
Get-EnvironmentInformation

Expected behavior

IsAdmin           : False
IsLinux           : False
IsCoreCLR         : False
IsWindows         : True
IsMacOS           : False
nugetPackagesRoot : C:\Users\MarkLocal\.nuget\packages

Actual behavior

IsAdmin           : False
IsLinux           : False
IsCoreCLR         : True
IsWindows         : True
IsMacOS           : False
nugetPackagesRoot : C:\Users\MarkLocal\.nuget\packages

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.15063.726
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.726
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Activity

  1. iSazonov commented on Nov 30, 2017

    @iSazonov
    Collaborator

    /cc Steve Lee (@SteveL-MSFT) Maybe we should still remove $IsCoreCLR?

  2. markekraus commented on Nov 30, 2017

    @markekraus
    ContributorAuthor

    Ilya (@iSazonov) This is unrelated to $IsCoreCLR.

    Get-EnvironmentInformation is used inside the build.psm1 and packaging.psm1 only. The IsCoreClr key of the returned hashtable is used here

    if (-not $Environment.IsCoreCLR) {

    and here

    if ((-not $NoNewWindow) -and ($Environment.IsCoreCLR)) {

  3. iSazonov commented on Nov 30, 2017

    @iSazonov
    Collaborator

    Ah, sorry - today is a busy day.

    I can not repo on my computer - both [System.Runtime.InteropServices.RuntimeInformation] and [System.Runtime.InteropServices.OSPlatform] throw. I think you load some assemblies in Windows PowerShell.

  4. markekraus commented on Nov 30, 2017

    @markekraus
    ContributorAuthor
  5. iSazonov commented on Nov 30, 2017

    @iSazonov
    Collaborator

    I am on 4.6.1

  6. SteveL-MSFT commented on Nov 30, 2017

    @SteveL-MSFT
    Member

    I can repro this after installing .Net 4.7.1. I think it would be fine to change the logic to assume Windows PowerShell 5.1 so we can use $PSVersionTable.PSEdition to determine if running on CoreCLR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions