psake / psake

A build automation tool written in PowerShell
https://psake.dev
MIT License
1.56k stars 269 forks source link

Alias error with Exec on Linux #328

Open paulhey opened 1 year ago

paulhey commented 1 year ago

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)

  1. Install Powershell 7.3.0
  2. Install psake powershell module (4.9.0)
  3. Create a psakefile.ps1 with an Exec statement in it
  4. 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

ModuleType Version PreRelease Name ExportedCommands


Script 4.9.0 psake {Assert, Exec, FormatTaskName, Framework…}

* Operating System and PowerShell version:
```terminal
❯ $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Linux 6.0.6-76060006-generic #202210290932~1669062050~22.04~d94609a SMP PREEMPT_DYNAMIC Mon N
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
HeyItsGilbert commented 2 months ago

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.