Search code examples
delphipowershelldelphi-xe2build-events

How to use an ampersand sign in a build event?


I'm trying to figure out how to call a PowerShell script with spaces in the filename as a Delphi build event.

From CMD I have to call powershell.exe -Command "& 'Filename With Spaces.ps1'" which works fine.

Delphi on the other hand doubles the ampersand sign and is trying to turn the command into two commands.

I have tried to set this as the build event:

powershell.exe -Command "& '$(PROJECTDIR)\Prebuild.ps1' $(PROJECTDIR)"

What gets executed by MSBuild is:

powershell.exe -Command "&& 'D:\SVN\AccuLib 3.0\VCLUI\Prebuild.ps1' D:\SVN\AccuLib 3.0\VCLUI"

So what does it take to call a ps1 file containing spaces from a Delphi build event?


Solution

  • Try the File parameter instead, it doesnt require an ampersand:

    powershell.exe -File "Filename With Spaces.ps1"