Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
zacharyshupp opened this issue Nov 24, 2023 · 4 comments
Closed
5 tasks done
Labels
Issue-Bug Issue has been identified as a bug in the product Issue-Regression The issue is a regression Resolution-Fixed The issue is fixed.

Comments

@zacharyshupp
Copy link

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

@zacharyshupp zacharyshupp added the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 24, 2023
@trackd
Copy link

trackd commented Nov 24, 2023

My guess is that its related to
Constrained Language AUDIT Mode
See #20719, #20768, #20767

Guessing the policy does not apply to pwsh which run from nonstandard path / installation.

@SteveL-MSFT SteveL-MSFT added Issue-Bug Issue has been identified as a bug in the product Issue-Regression The issue is a regression labels Dec 12, 2023
@daxian-dbw
Copy link
Member

daxian-dbw commented Mar 13, 2024

@zacharyshupp Please be noted that you are running PowerShell with the WDAC Audit mode turned on. Not sure if you really mean to do that.

PowerShell 7.4.0
[Constrained Language AUDIT Mode : No Restrictions]
PS C:\Program Files\PowerShell\7> cd D:\Development\ps-module-base

Anyways, I think the issue you ran into was resolved by #20913. The PSReadLine repo also uses InvokeBuild module for the build, and it works fine in PowerShell v7.4.1 under the "Constrained Language AUDIT Mode" (see the screenshot below).

Please upgrade to v7.4.1 and give it another try. If it still fails for you, then please open another issue with repro steps. The repository https://github.com/zacharyshupp/ps-module-base from your repro steps above is not accessible. Is it a private repo by any chance?

image

GitHub
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.

@daxian-dbw daxian-dbw added Resolution-Fixed The issue is fixed. and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Mar 13, 2024
Copy link
Contributor

This issue has been marked as fixed and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Copy link
Contributor

microsoft-github-policy-service bot commented Mar 15, 2024

📣 Hey @zacharyshupp, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Issue has been identified as a bug in the product Issue-Regression The issue is a regression Resolution-Fixed The issue is fixed.
Projects
None yet
Development

No branches or pull requests

5 participants
@daxian-dbw @zacharyshupp @SteveL-MSFT @trackd and others