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?
MSBuild is the build engine that Visual Studio uses to process your project file when it performs a build. A build event in the IDE results in an MSBuild target in the project file. You can use any MSBuild property that is available in the target in your project file (for example, $(OutDir) or $(Configuration) ) .
PreBuild and PostBuild aren't only used for hiding or unhiding pages. The main difference really is that PreBuild fires before any peoplecode code event on all the rows and fields in the component such as FieldDefault and RowInit. PostBuild runs after that.
PostBuildEvent. This event executes after the build finishes.
Go to the Solution Explorer the right-click the project then select Properties then go to the Build Events tab. Now if you build the project based upon the selection of configuration name , the Web. config file will be updated.
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.
I'm using Visual Studio 2010 on Windows 7 64-bits.
I found a solution that's better to my liking, I'm chaining commands together with && ^
, for example, editing my .vcxproj xml file like so:
<PreBuildEvent> <Command>echo "hello 1" && ^ echo "hello 2" && ^ echo "hello 3"</Command> <Message>Performaing pre-build actions ...</Message> </PreBuildEvent>
I've chained three commands together. The '&&' tells the shell to stop executing if the previous command errors out.
Note, in the .xml file, one can't use &&
directly, so '& amp;& amp;' must be used instead. Also note the use of the ^
character, this is the cmd shell's line continuation character (like BASH's \
char).
Each new command must start at the beginning of the line. Using this approach, one can chain as many commands as one wants, but if any fail, the rest in the chain won't get executed.
Here's my actual usecase, I'm performing some environment checks with a Python script, followed by copying my pre-compiled header's debug file to another sub-project's directory:
<PreBuildEvent> <Command>C:\Python27\python.exe "$(SolutionDir)check_path.py" 32 && ^ copy "$(SolutionDir)h1ksim_lib\vc$(PlatformToolsetVersion).pdb" "$(IntDir)" /-Y > nul</Command> <Message>Performaing pre-build actions ...</Message> </PreBuildEvent>
The > nul
usage on the copy command prevents any output showing up in the build window, so my teammates won't get freaked out when it says 0 file(s) copied.
Reference to sharing pre-compiled headers between sub-projects is here:
Sharing precompiled headers between projects in Visual Studio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With