2013-09-30 34 views
16

我们能有这样的事情:VS2010:我们可以有多个如果在后生成事件?

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 

我已经试过了,但它不工作。错误代码是255.

回答

28

你可以有很多条件语句,只要你想,只是由新的生产线将它们分开,失去别人

因此改变

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

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

,它会编译运行得很好

注意:命令将逐行解释s作为一个DOS批处理文件,因此重要的是在与块中最后一个命令相同的行中放置左括号“(”与if语句和右括号相同的行)“。

4

如果您的后构建逻辑变得越来越复杂,我建议将其移动到外部文件。例如,下面的生成后事件:

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

执行项目目录的批处理文件PostBuild.cmd,传递$(ConfigurationName)作为参数。您也可以传递其他参数,如$(TargetPath)。

然后,您可以实现包括多个if语句在内的任何内容,更重要的是,无需运行Visual Studio构建即可进行调试。

相关问题