Best way to increment assembly version for multiple projects

336 views
Skip to first unread message

justin.p...@jembi.org

unread,
Dec 1, 2015, 9:30:57 AM12/1/15
to MSBuild Community Tasks
Hi Everyone


I have followed a tutorial regarding the usage of the Version Task to increment the assembly version for multiple projects in a solution.

Is the suggested method the following:

For each project, modify each project to use Version Task to create a separate versioninfo.cs file (or similar) int the "BeforeBuild"

This is what I have so far

 <!-- New increment version step-->
  <Target Name="IncrementVersion" Condition="'$(SkipIncrementAssemblyVersion)' != 'true'">
    <Message Importance="high" Text="Incrementing build number..." />
    <Version VersionFile="$(SolutionDir)\.build\Version.txt" StartDate="01/31/2015" RevisionType="Increment">
      <Output TaskParameter="Major" PropertyName="Major" />
      <Output TaskParameter="Minor" PropertyName="Minor" />
      <Output TaskParameter="Build" PropertyName="Build" />
      <Output TaskParameter="Revision" PropertyName="Revision" />
    </Version>
    <PropertyGroup>
      <BuildNumber>$(Major).$(Minor).$(Build).$(Revision)</BuildNumber>
    </PropertyGroup>
    <Message Importance="high" Text="Incrementing build number to $(BuildNumber)" />
    <AssemblyInfo CodeLanguage="CS" OutputFile="Properties\VersionInfo.cs" AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)" AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" />
  </Target>

Then to run it I call "MSBuild [project name etc] /t:IncrementVersion


Is there a more elegant way of doing this?  The other problem is that the new version number is only visible in the Properties window of the DLL when I build the project through Visual Studio.  Is this supposed to happen?



Colin Dabritz

unread,
Apr 4, 2016, 2:13:15 PM4/4/16
to MSBuild Community Tasks
We had lots of challenges around versioning as well. If you increment during build, how does that get back to source control? If not, where does the version come from?

For us, we were in TFS and VSTS on various projects. Both expose build variables with the version, and will automatically increment the 'revision' value.

We chose the build environment version value as the 'source of truth' for versioning, and used 0.0.0.0 for a fallback for local development versions.

We cover both TFS and VSTS builds with these lines:

<SourceVersion Condition="'$(TF_BUILD_SOURCEGETVERSION)' != ''">$(TF_BUILD_SOURCEGETVERSION)</SourceVersion>
<SourceVersion Condition="'$(BUILD_SOURCEVERSION)' != ''">$(BUILD_SOURCEVERSION)</SourceVersion>

You can pass that in to AssemblyVersion.
Reply all
Reply to author
Forward
0 new messages