You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:<processor>
where <processor> 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:
Fallback to powershell
Fail the task
Alternative Designs
No response
The text was updated successfully, but these errors were encountered:
The example you mention overrides the ToolName property on the ToolTask to be powershell.exe.
But my point is not generating a Task instance for this - the point is to allow you to use a PowerShell script directly in for example the PreBuildEvent.
Try for example to put the following in the PreBuildEvent field in the Project properties page:
Get-ChildItems $(TargetDir)
and then build the project.
When I tried, I got failing build.
The contents of the PreBuildEvent field is in the project file (for Sdk style projects) transformed into a Target containing an Exec task. And the Exec task defaults to cmd.exe for Windows or sh for non-Windows.
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 specifyingToolPath
andToolExe
parameters to Exec task having them point to for examplepwsh.exe
does not help, because there is some internal processing and adding command line parameters specific tocmd.exe
Having support for Powershell scripts in Exec task adds a high level of flexibility to
PreBuildEvent
andPostBuildEvent
as Powershell has a log more features thancmd.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
andPostBuildEvent
, an option could be to specify the wanted command processor in a comment line first in the script. Then based on this comment line, theExec
class resolves the command processor.The comment could be something like
where
<processor>
would be eithercmd
,pwsh
orpowershell
. If no specified,cmd
would be default as today.If
pwsh
is not installed, there are two options:powershell
Alternative Designs
No response
The text was updated successfully, but these errors were encountered: