Skip to content

InvokeBuild Fails to run when using PowerShell 7.4.0 installed via MSI or Windows Store #20777

@zacharyshupp

Description

@zacharyshupp

Prerequisites

Steps to reproduce

The below steps cover how to test this issue using my test repo. I originally opened an issue with InvokeBuild. In our troubleshooting we noticed that if we used the zip archive for PowerShell the below steps work but something within the MSI/Windows Store build cause this to fail and we can't figure it out.

Steps

  1. Install PowerShell 7.4.0 via MSI
  2. Clone https://github.com/zacharyshupp/ps-module-base
  3. launch 7.4.0 and navigate to directory you cloned module to
  4. type .\build.ps1 -InstallDependencies -Task Build, press enter.

Once you press Enter, it should download some modules that's needed for the build process but then it triggers invoke-build to build the module in the output directory it will create. If I run this code in 7.3.10 I have no issues, once 7.4 is installed via MSI this stops working.

Expected behavior

PS D:\Development\ps-module-base> .\build.ps1 -InstallDependencies -Task Build
Tool 'gitversion.tool' (version '5.12.0') was restored. Available commands: dotnet-gitversion                           
Restore was successful.
Build Build D:\Development\ps-module-base\tools\build.tasks.ps1

MyToolbox

Importing Build Support Functions

===============================================================================
Task /Build/Clean : Remove any existing builds
  - Removed Previous Output Directory
  - Created new Output Directory
-------------------------------------------------------------------------------
Done /Build/Clean, 00:00:00.0349875

===============================================================================
Task /Build/SetEnv : Configure Local Dev Enviroment
  - There are 1 Modules to load.
  - Imported 'Pester' version '5.5.0'
-------------------------------------------------------------------------------
Done /Build/SetEnv, 00:00:03.3549765

===============================================================================
Task /Build : Build Module from Source
  - Created Module root directory
  - Imported Runtime Varaibles
  - Imported Function 'Get-Something.ps1'
  - Imported Function 'Test-Something.ps1'
  - Created PSD1
-------------------------------------------------------------------------------
Done /Build, 00:00:03.5063925

Build succeeded. 3 tasks, 0 errors, 0 warnings 00:00:03.6888449

Actual behavior

PowerShell 7.4.0
[Constrained Language AUDIT Mode : No Restrictions]
PS C:\Program Files\PowerShell\7> cd D:\Development\ps-module-base
PS D:\Development\ps-module-base> .\build.ps1 -InstallDependencies -Task Build
Tool 'gitversion.tool' (version '5.12.0') was restored. Available commands: dotnet-gitversion

Restore was successful.
Invoke-Build.ps1: D:\Development\ps-module-base\build.ps1:146
Line |
 146 |      Invoke-Build -Task $Task -File $projectPath['BuildTasks']
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'File' cannot be found on this object. Verify that the property exists and can be set.

Error details

PS D:\Development\ps-module-base> Get-Error

Exception             :
    Type       : System.Exception
    TargetSite :
        Name          : ThrowTerminatingError
        DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation,
Version=7.4.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message    : The property 'File' cannot be found on this object. Verify that the property exists and can be set.
    Source     : System.Management.Automation
    HResult    : -2146233088
    StackTrace :
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
CategoryInfo          : InvalidArgument: (:) [Invoke-Build.ps1], Exception
FullyQualifiedErrorId : Invoke-Build.ps1
InvocationInfo        :
    MyCommand        : Invoke-Build.ps1
    ScriptLineNumber : 146
    OffsetInLine     : 5
    HistoryId        : 2
    ScriptName       : D:\Development\ps-module-base\build.ps1
    Line             : Invoke-Build -Task $Task -File $projectPath['BuildTasks']

    Statement        : Invoke-Build -Task $Task -File $projectPath['BuildTasks']
    PositionMessage  : At D:\Development\ps-module-base\build.ps1:146 char:5
                       +     Invoke-Build -Task $Task -File $projectPath['BuildTasks']
                       +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : D:\Development\ps-module-base
    PSCommandPath    : D:\Development\ps-module-base\build.ps1
    InvocationName   : Invoke-Build
    CommandOrigin    : Internal
ScriptStackTrace      : at *Die, D:\Development\ps-module-base\dependencies\InvokeBuild\5.10.4\Invoke-Build.ps1: line
31
                        at <ScriptBlock><DynamicParam><trap>,
D:\Development\ps-module-base\dependencies\InvokeBuild\5.10.4\Invoke-Build.ps1: line 43
                        at <ScriptBlock><DynamicParam>,
D:\Development\ps-module-base\dependencies\InvokeBuild\5.10.4\Invoke-Build.ps1: line 109
                        at <ScriptBlock>, D:\Development\ps-module-base\build.ps1: line 146
                        at <ScriptBlock>, <No file>: line 1PS D:\Development\ps-module-base> Get-Error

Exception             :
    Type       : System.Exception
    TargetSite :
        Name          : ThrowTerminatingError
        DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation,
Version=7.4.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message    : The property 'File' cannot be found on this object. Verify that the property exists and can be set.
    Source     : System.Management.Automation
    HResult    : -2146233088
    StackTrace :
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
CategoryInfo          : InvalidArgument: (:) [Invoke-Build.ps1], Exception
FullyQualifiedErrorId : Invoke-Build.ps1
InvocationInfo        :
    MyCommand        : Invoke-Build.ps1
    ScriptLineNumber : 146
    OffsetInLine     : 5
    HistoryId        : 2
    ScriptName       : D:\Development\ps-module-base\build.ps1
    Line             : Invoke-Build -Task $Task -File $projectPath['BuildTasks']

    Statement        : Invoke-Build -Task $Task -File $projectPath['BuildTasks']
    PositionMessage  : At D:\Development\ps-module-base\build.ps1:146 char:5
                       +     Invoke-Build -Task $Task -File $projectPath['BuildTasks']
                       +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : D:\Development\ps-module-base
    PSCommandPath    : D:\Development\ps-module-base\build.ps1
    InvocationName   : Invoke-Build
    CommandOrigin    : Internal
ScriptStackTrace      : at *Die, D:\Development\ps-module-base\dependencies\InvokeBuild\5.10.4\Invoke-Build.ps1: line
31
                        at <ScriptBlock><DynamicParam><trap>,
D:\Development\ps-module-base\dependencies\InvokeBuild\5.10.4\Invoke-Build.ps1: line 43
                        at <ScriptBlock><DynamicParam>,
D:\Development\ps-module-base\dependencies\InvokeBuild\5.10.4\Invoke-Build.ps1: line 109
                        at <ScriptBlock>, D:\Development\ps-module-base\build.ps1: line 146
                        at <ScriptBlock>, <No file>: line 1

Environment data

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

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.4-regressionRegression in 7.4Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions