Skip to content

Allow automatic variable Is* inside PowerShell module manifest file #9386

@fMichaleczek

Description

@fMichaleczek

NugetPackage have sometimes 2 distincts dll for Windows/Unix plateform.
It's not possible to determine which OS is running from a PowerShell module manifest file.
This issue should be resolved in early PS 7.0 cycle because Net.Core 3.0 will add more scenarios with cross plateforms.

Steps to reproduce

Add a condition with variable IsWindows into the property RequiredAssemblies inside a PowerShell module manifest file.

RequiredAssemblies =  @(
    if ( $IsWindows ) { 
        '.\bin\LibName\runtimes\win\lib\netstandard2.0\LibName.dll' 
    }
    else { 
       '.\bin\LibName\runtimes\unix\lib\netstandard2.0\LibName.dll' 
    }
)

Expected behavior

PowerShell module manifest file is loaded.

Actual behavior

PowerShell Error

import-module : The module manifest 'ModuleName.psd1' could not be processed because it is not a valid PowerShell module manifest file. Remove the elements that are not permitted: At ModuleName.psd1:50 char:10
+     if ( $IsWindows ) {
+          ~~~~~~~~~~
A variable that cannot be referenced in restricted language mode or a Data section is being referenced. Variables that can be referenced include the following: $PSCulture, $PSUICulture, $true, $false, $null, $PSScriptRoot, $PSEdition, $EnabledExperimentalFeatures.

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-DuplicateThe issue is a duplicate.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions