VS2010: Can we have multiple if in post-build event?

女生的网名这么多〃 提交于 2019-12-31 21:21:09

问题


Can we have something like this:

if "Debug"=="$(ConfigurationName)"
(
  goto :nocopy
)
else if "Release"=="$(ConfigurationName)"
(
  del "$(TargetPath).config"
  copy "$(ProjectDir)\App.Release.config" "$(TargetPath).config"
)
else if "ReleaseBeta"=="$(ConfigurationName)"
(
  del "$(TargetPath).config"
  copy "$(ProjectDir)\App.ReleaseBeta.config" "$(TargetPath).config"
)
else if "ReleaseProduction"=="$(ConfigurationName)"
(
  del "$(TargetPath).config"
  copy "$(ProjectDir)\App.ReleaseProduction.config" "$(TargetPath).config"
)
    :nocopy

I've tried it but it doesn't work. The error code is 255.


回答1:


You can have as many conditional statements as you want, just separate them by new line and lose else

So change

if "Debug"=="$(ConfigurationName)"
(
  goto :nocopy
)
else if...

To

if "Debug" == "$(ConfigurationName)" (goto :nocopy)
if "Release" ==" $(ConfigurationName)" (
    del "$(TargetPath).config"
    copy "$(ProjectDir)\App.Release.config" "$(TargetPath).config" )
if ...

and it will compile and run just fine

Note: The commands will be interpreted line-by-line the same way as a DOS batch file, so it is important to place the opening parenthesis “(” in the same line as the if statement and the closing parenthesis ")" in the same line as the last command in the block.




回答2:


If your post-build logic is getting complicated, I'd suggest moving it to an external file. For example, the following post-build event:

CALL "$(ProjectDir)PostBuild.cmd" $(ConfigurationName)

executes a batch file PostBuild.cmd in the project-directory, passing $(ConfigurationName) as a parameter. You could also pass other parameters, such as $(TargetPath).

You can then implement whatever you want including multiple if statements, and more importantly, debug it without running a Visual Studio build.



来源:https://stackoverflow.com/questions/19088271/vs2010-can-we-have-multiple-if-in-post-build-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!