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

tesicg picture tesicg · Sep 30, 2013 · Viewed 20.4k times · Source

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.

Answer

Davor Zlotrg picture Davor Zlotrg · Sep 30, 2013

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.