Wednesday, May 25, 2011

MSBuild Building multiple Configurations and Platforms at the same time

Here is a MSBuild project file that allows you to specify multiple configurations and platforms. The advantage of this approach is that you get a single report with all the build results.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Rebuild" ToolsVersion="4.0">
<ItemGroup>
<ConfigurationList Condition=" '@(ConfigurationList)' == '' and $(Configuration) != '' " Include="$(Configuration.Split(';'))" />
<ConfigurationList Condition=" '@(ConfigurationList)' == '' " Include="Debug" />
<PlatformList Condition=" '@(PlatformList)' == '' and $(Platform) != '' " Include="$(Platform.Split(';'))" />
<PlatformList Condition=" '@(PlatformList)' == '' " Include="Xbox 360" />
<TargetList Condition=" '@(TargetList)' == '' and $(Targets) != '' " Include="$(Targets.Split(';'))" />
<TargetList Condition=" '@(TargetList)' == '' " Include="Rebuild" />
<ProjectList Condition=" '@(ProjectList)' == '' and $(Projects) != '' " Include="$(Projects.Split(';'))" />
<ProjectList Condition=" '@(ProjectList)' == '' " Include="$(MSBuildProjectDirectory)\Test.sln" />
ItemGroup>
<Target Name="Rebuild" Outputs="%(PlatformList.Identity)">
<PropertyGroup>
<CurrentPlatform>%(PlatformList.Identity)CurrentPlatform>
PropertyGroup>
<MSBuild Projects="@(ProjectList)"
Properties="Configuration=%(ConfigurationList.Identity);Platform=$(CurrentPlatform);"
Targets="@(TargetList)"
SkipNonexistentProjects="true"
/>
Target>
Project>

usage:
msbuild BuildProject.proj /p:Projects="ProjA;ProjB" /p:Configuration="Debug;Release" /p:Platform="XBox 360;Win32;x86" /p:Targets="target"
examples:
msbuild BuildProject.proj
-- this will rebuild default solution for Debug|Xbox 360

msbuild BuildProject.proj /p:Projects="Test2.sln;Test1.sln" ^
/p:Configuration="Debug;Release" ^
/p:Platform="XBox 360;Win32;x86" ^
/p:Targets="clean;build"
-- this will build everything

No comments:

Post a Comment