Just Code‎ > ‎

Automatic build version counter for visual studio projects

posted Feb 14, 2010, 3:40 AM by Peter Henell
Updates all assemblies in the sollution
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

  <PropertyGroup>
    <SolutionRoot>..</SolutionRoot>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReferences Include="$(SolutionRoot)\SPAK2.sln" />
    <AssemblyInfoFiles Include="$(SolutionRoot)\**\AssemblyInfo.cs" />
  </ItemGroup>

  <Target Name="BuildSolution">
    <!-- Update version number revision -->
    <Version VersionFile="version.txt" RevisionType="Increment">
      <Output TaskParameter="Major" PropertyName="Major" />
      <Output TaskParameter="Minor" PropertyName="Minor" />
      <Output TaskParameter="Build" PropertyName="Build" />
      <Output TaskParameter="Revision" PropertyName="Revision" />
    </Version>

    <Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>

    <!-- Update AssemblyInfo files -->
    <FileUpdate
      Files='@(AssemblyInfoFiles)'
      Regex='(?&lt;ver&gt;assembly: Assembly.*?Version\(")\d+\.\d+\.\d+\.\d+'
      ReplacementText='${ver}$(Major).$(Minor).$(Build).$(Revision)' />

    <!-- Rebuild projects -->
    <MSBuild
      Projects="@(ProjectReferences)"
      Targets="Rebuild">
      <Output TaskParameter="TargetOutputs"
              ItemName="AssembliesBuiltByChildProjects" />
    </MSBuild>
  </Target>

</Project>
Comments