我想在PostBuild事件中使用局部变量,但我不知道如何在其中使用。这是我的Post-Build事件命令(param
是通过msbuild /p开关传递的命名参数):
set fold=$(TargetDir)
if defined param (set fold=$(TargetDir)$(param)\)
if not exist "%fold%" md "%fold%"
copy /y "$(TargetPath)" "%fold%"
构建解决方案时,我遇到了以下问题:
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.
如果我将
%fold%
更改为$(fold)
,我会得到另一个结果,但它也是错误的: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.
我做错了什么?