Migrating a legacy .NET project to Visual Studio 2022. Found I was not able to run multiple commands for either Pre-Build or Post-Build. The behavior wasn't consistent when switching between Debug/Release even once I got the syntax correct. I anticipate there is possibly a bug here.
In Debug configuration, it would error out using XCOPY /Y /F no matter what I tried. Error code 2 and 4 being the most common while Release worked. I had trouble gauging what was a syntax error and what was just an error. XCOPY /Y /F worked just fine in CMD/PowerShell.
Executing multiple commands becomes possible (even with conditionals) only after "bubbling" the commands ( ... ).
i.e. going from this
copy $(TargetDir)x64\SQLite.Interop.dll $(TargetDir)SQLite.Interop_x64.dll
copy $(TargetDir)x86\SQLite.Interop.dll $(TargetDir)SQLite.Interop_x86.dll
if $(ConfigurationName) == Release (
call "C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe" sign /t http://timestamp.sectigo.com /fd sha256 $(TargetPath)
)
(copy $(TargetDir)x64\SQLite.Interop.dll $(TargetDir)SQLite.Interop_x64.dll)
(copy $(TargetDir)x86\SQLite.Interop.dll $(TargetDir)SQLite.Interop_x86.dll)
(if $(ConfigurationName) == Release (
call "C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe" sign /t http://timestamp.sectigo.com /fd sha256 $(TargetPath)
))
Additional tidbit, since ( ) are the special characters, if you need to escape them, use caret, i.e. ^)
Stackoverflow: Post-build event with multiple if/copy combinations only execute if first file does not exist