While doing Powershell development on Linux I encountered an issue running a psakefile.ps1.
The component:
...
Task GitPull {
Exec { git pull }
}
...
Expected Behavior
❯ invoke-psake GitPull
psake version 4.9.0
Copyright (c) 2010-2018 James Kovacs & Contributors
Executing GitPull
Already up to date.
psake succeeded executing psakefile.ps1
----------------------------------------------------------------------
Build Time Report
----------------------------------------------------------------------
Name Duration
---- --------
GitPull 00:00:01.370
Total: 00:00:01.385
Current Behavior
❯ invoke-psake GitPull
psake version 4.9.0
Copyright (c) 2010-2018 James Kovacs & Contributors
Executing GitPull
Error: 2022-12-01 1:24:56 p.m.:
At /home/paulhey/Projects/labcollector/psakefile.ps1:377 char:3 + Exec { git pull } + ~~~~~~~~~~~~~~~~~ [<<==>>] Exception: Command '' was not found. The specified command must be an executable.
Possible Solution
Current work around is to remove the alias so I can continue to run the script.
❯ Remove-Alias exec
Or add this line to your Profile script
Steps to Reproduce (for bugs)
Install Powershell 7.3.0
Install psake powershell module (4.9.0)
Create a psakefile.ps1 with an Exec statement in it
Run the Invoke-PSake against the task with the Exec statement
Context
I was attempting to use my psakefile to handle some automation steps. After the error was thrown I had though there was an issue with my psakefile (typo, etc) and so I opened it up into VSCode where I discovered that it was reporting Exec as an alias for Switch-Process (I found this online documentation). I may also have to open an issue with PSScriptAnalyzer or VSCode-PowerShell as the analyzer reports it as an alias instead of a function and the formatting tool wants to replace it as such.
So with some additional troubleshooting, I am unable to reproduce this in PowerShell 7.2.* and with a bit of digging I found a PR on the main PowerShell repo for PowerShell 7.3.1, which looks to create a colliding function instead of an alias.
I have been unable to reproduce in Windows, as the alias Exec and function Switch-Process don't exist there.
Your Environment
Module version used:
❯ Get-Module psake
ModuleType Version PreRelease Name ExportedCommands
This will likely require removing or replacing exec. This means it should happen in a new major version. Leaving this for someone to pick up or I'll try to tackle it in the future.
While doing Powershell development on Linux I encountered an issue running a
psakefile.ps1
. The component:Expected Behavior
Current Behavior
Possible Solution
Current work around is to remove the alias so I can continue to run the script.
Or add this line to your Profile script
Steps to Reproduce (for bugs)
Exec
statement in itInvoke-PSake
against the task with theExec
statementContext
I was attempting to use my psakefile to handle some automation steps. After the error was thrown I had though there was an issue with my psakefile (typo, etc) and so I opened it up into VSCode where I discovered that it was reporting
Exec
as an alias forSwitch-Process
(I found this online documentation). I may also have to open an issue with PSScriptAnalyzer or VSCode-PowerShell as the analyzer reports it as an alias instead of a function and the formatting tool wants to replace it as such. So with some additional troubleshooting, I am unable to reproduce this in PowerShell 7.2.* and with a bit of digging I found a PR on the main PowerShell repo for PowerShell 7.3.1, which looks to create a colliding function instead of an alias.I have been unable to reproduce in Windows, as the alias
Exec
and functionSwitch-Process
don't exist there.Your Environment
ModuleType Version PreRelease Name ExportedCommands
Script 4.9.0 psake {Assert, Exec, FormatTaskName, Framework…}