Skip to content

Instantly share code, notes, and snippets.

@heaths
Created October 6, 2017 17:01
Show Gist options
  • Save heaths/5dae0d427c9e6997f3aed52e59af8508 to your computer and use it in GitHub Desktop.
Save heaths/5dae0d427c9e6997f3aed52e59af8508 to your computer and use it in GitHub Desktop.
Example MSBuild Traversal
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SerializeProjects>true</SerializeProjects>
</PropertyGroup>
<ItemGroup>
<Project Include="Samples.sln" />
<Project Include="Samples.sln">
<AdditionalProperties>Platform=x64</AdditionalProperties>
</Project>
<Project Include="pkg\dirs.proj" />
</ItemGroup>
<Import Project="lib\Traversal.targets" />
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<BuildInParallel Condition="'$(BuildInParallel)' == ''">true</BuildInParallel>
</PropertyGroup>
<ItemDefinitionGroup>
<Project>
<AdditionalPropeties />
<BuildInParallel>$(BuildInParallel)</BuildInParallel>
</Project>
</ItemDefinitionGroup>
<Target Name="BuildAllProjects">
<!-- To Serialize we use msbuild's batching functionality '%' to force it to batch all similar projects with the same identity
however since the project names are unique it will essentially force each to run in its own batch -->
<MSBuild Targets="Build" Projects="@(Project)" Condition="'$(SerializeProjects)'=='true'" BuildInParallel="%(BuildInParallel)" Properties="Dummy=%(Identity)" />
<MSBuild Targets="Build" Projects="@(Project)" Condition="'$(SerializeProjects)'!='true'" BuildInParallel="$(BuildInParallel)" />
</Target>
<Target Name="CleanAllProjects">
<!-- To Serialize we use msbuild's batching functionality '%' to force it to batch all similar projects with the same identity
however since the project names are unique it will essentially force each to run in its own batch -->
<MSBuild Targets="Clean" Projects="@(Project)" Condition="'$(SerializeProjects)'=='true'" BuildInParallel="%(BuildInParallel)" Properties="Dummy=%(Identity)" />
<MSBuild Targets="Clean" Projects="@(Project)" Condition="'$(SerializeProjects)'!='true'" BuildInParallel="$(BuildInParallel)" />
</Target>
<PropertyGroup>
<TraversalBuildDependsOn>
BuildAllProjects;
$(TraversalBuildDependsOn);
</TraversalBuildDependsOn>
<TraversalCleanDependsOn>
CleanAllProjects;
$(TraversalCleanDependsOn);
</TraversalCleanDependsOn>
</PropertyGroup>
<Target Name="Build" DependsOnTargets="$(TraversalBuildDependsOn)" />
<Target Name="Clean" DependsOnTargets="$(TraversalCleanDependsOn)" />
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment