I want to use local variable inside the PostBuild event, but I could not understand how to use it inside. Here my Post-Build event commands (param
is the named parameter that can be passed through the msbuild /p switch):
set fold=$(TargetDir)
if defined param (set fold=$(TargetDir)$(param)\)
if not exist "%fold%" md "%fold%"
copy /y "$(TargetPath)" "%fold%"
When building the solution I get:
msbuild PrePostBuildEvents.sln /p:param=ext
...
PostBuildEvent:
set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\
if defined param (set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\ext\)
if not exist "%fold%" md "%fold%"
copy /y "G:\prj\work\PrePostBuildEvents\bin\Debug\PrePostBuildEvents.dll" "%fold%"
The file cannot be copied onto itself.
0 file(s) copied.
If I change %fold%
to $(fold)
, I get another result, but it is also wrong:
PostBuildEvent:
set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\
if defined param (set fold=G:\prj\work\PrePostBuildEvents\bin\Debug\ext\)
if not exist "" md ""
copy /y "G:\prj\work\PrePostBuildEvents\bin\Debug\PrePostBuildEvents.dll" ""
The filename, directory name, or volume label syntax is incorrect.
0 file(s) copied.
What I'm doing wrong?