views:

773

answers:

4

I've followed a blog post by Scott Hanselman for managing configuration with PreBuild Events and have it working fine.

I now want to split up my configuration into a couple of different files, so need to exectue the command again before the build. The problem is the PreBuild event text all gets executed as one console command. How can I split it up as several commands?

A: 

You should be able to put the commands on a separate line, and then each command will be executed in sequence. Alternatively, a "cheater" way to do the same thing is as follows:

  • Create a second batch file that runs the desired portion of new functionality, then create a parent batch that runs the two component batch files, and run that new batch in your pre-build event. For example: batch1.bat modifies file 1, batch2.bat modifies file 2, then batch3.bat runs both batch1.bat and batch2.bat
MBillock
They are on separate lines, but they seem to be getting executed as one. I have considered bat file approach but it seems like a work-around rather than a solution.
Kirschstein
Strange. I'd offer other suggestions (like adding semicolons as separators), but I'd just be grasping at straws. Sorry!
MBillock
+6  A: 

Turns out the problem is Scott's example doesn't include the call command at the start of the line. This is fine as long as you don't want to execute the .bat file multiple times with different parameters.

This:

call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)connectionStrings.config.$(ConfigurationName)" "$(ProjectDir)connectionStrings.config"
call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)appSettings.config.$(ConfigurationName)" "$(ProjectDir)appSettings.config"

worked fine for me.

Kirschstein
In VS2008 putting multiple CMD files on separate lines did not work. VS only called the first script on build. I added CALL in front of each line and then it all worked.
emddudley
A: 

I had similar problem and "call" worked for me. Thanks community.

Pinal Bhatt
A: 

Same here, new line doesn't work while call is working