In a previous post I’ve described how to do product/build versioning with MSBuild. Another common build aspect is building different flavors of code: Debug vs. Release.
All the projects I work on now have a very simple MSBuild script that allows you to build either Debug or Release, defaulting to Debug for developers. Our CruiseControl configurations build Release. Comes a shared libraries project, which needs to do Debug, Release or both. How can I accomplish this with MSBuild?
Default Configuration
Let’s define a property for the default configuration, ie. when no Configuration is specified on the command line.
Multiple Configurations
What if multiple configurations were specified? For example, Debug;Release. We want to transform a single property into an array of task parameters. There’s a brain-twisting way of doing this with MSBuild.
It seems that the above code does nothing, but it creates an item called Configuration that can be specified as input to another target.
Try it.
Target Inputs
Finally, change all the targets that depend on the configuration name accordingly and use %(Configuration.Identity) rather than $(Configuration) in those tasks.