【发布时间】:2014-01-19 17:15:06
【问题描述】:
我想在PostBuild event 中使用局部变量,但我不明白如何在里面使用它。这里是我的构建后事件命令(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.
我做错了什么?
【问题讨论】:
-
我不在我的 Windows 机器附近,但是在 VS 的项目属性中有一个资源选项卡,我想你在那里定义它。你可以检查一下,或者我稍后会在我靠近我的 Win 机器时检查
-
我假设我只能在那里定义一个常量字符串,但我需要一个可计算的,这取决于命名参数。
标签: c# variables msbuild post-build-event