add_custom_command: Some syntax not escaped by VERBATIM
add_custom_command(
COMMAND
"echo" "\$(TEST)"
VERBATIM
)
Expected generated project:
<Command>
setlocal
echo %24(TEST)
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
</Command>
Expected executed script:
echo $(TEST)
Expected Output:
$(TEST)
Actual generated project:
<Command>
setlocal
echo $(TEST)
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
</Command>
Actual executed script:
echo
Actual Output:
Cause:
$
and %
both require an additional round of escaping for generated shell script. Prior to handing off to the shell, msbuild also performs macro substitution of everything resembling a %(...)
or $(...)
pattern.
Specifically, the following substitution rules must all be applied in a second round on top of the batch
escaping logic already in place: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-special-characters?view=vs-2022 (Documentation also applies to older versions.)
Edited by Brad King