Support executing Powershell scripts in Exec task
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Summary
Extend the Exec task to support executing Powershell scripts either using pwsh.exe or powershell.exe
### Background and Motivation
Currently, the Exec task is hardcoded to use `cmd.exe` on Windows, and specifying `ToolPath` and `ToolExe` parameters to Exec task having them point to for example `pwsh.exe` does not help, because there is some internal processing and adding command line parameters specific to `cmd.exe`
Having support for Powershell scripts in Exec task adds a high level of flexibility to `PreBuildEvent` and `PostBuildEvent` as Powershell has a log more features than `cmd.exe` and batch scripts.
### Proposed Feature
Supporting Powershell as command prcoessor requires some changes in the `Exec` task class. These are centered around the places where the command tool is evaluated, where the potential batch file is written and the execution of the command is hanndled. As far as I can see, it will only be in this class, changes are required.
To avoid changing designers for `PreBuildEvent` and `PostBuildEvent`, an option could be to specify the wanted command processor in a comment line first in the script. Then based on this comment line, the `Exec` class resolves the command processor.
The comment could be something like
```
#!shell:
```
where `` would be either `cmd`, `pwsh` or `powershell`. If no specified, `cmd` would be default as today.
If `pwsh` is not installed, there are two options:
1. Fallback to `powershell`
2. Fail the task
### Alternative Designs
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.