5
votes

I'm using the MSBuild Community Task library to get the current SVN version an set that in my AssemblyInfo files to get the revision in the final compiled dll.

As you know SVN version can then be like "28" or "28M" - if there are modifications. If i do a MSBuild message and output the Revision property I see I get a 28M after modification but when updating the AsseblyInfo I keep getting only 28 in the version number ..?

I'd like to have the 28M in the version number to indicate the dll is built using a non-check in modification. How can I get that working?

<Target Name="Compile">
<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(SvnTool)">
  <Output TaskParameter="Revision" PropertyName="Revision" />
</SvnVersion>

<ItemGroup>
  <AssemblyInfoFiles Include="x.a\Properties\AssemblyInfo.cs" />
  <AssemblyInfoFiles Include="x.b\Properties\AssemblyInfo.cs" />
</ItemGroup>

<FileUpdate Files="@(AssemblyInfoFiles)"
            Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
            ReplacementText="$(MajorVersion).$(MinorVersion).$(Revision).0" />

<MSBuild  Projects="$(MSBuildProjectDirectory)\ConfigExplorer.sln" Targets="Rebuild" Properties="Configuration=$(BuildType);" />

1
You can't have 28M as the revision number because revision is declared as int in Version class: public int Revision { get; }. But you can use for example AssemblyInformationalVersionAttribute attribute instead to store any text you like.Igor Korkhov

1 Answers

4
votes

.Net assemblies version numbers are sternly typed. They are not just any string but ushorts which means they have a max of 65535 (see docs http://msdn.microsoft.com/en-us/library/cbf1574z.aspx). If you use the svn revision (as I did at one point) your build will break once it exceeds that magic number.

A scheme I also used that indicated developer builds vs. CI builds was to use versions in the form of {year}.{month}.{day}.{build} where the build number was specified with an extra build parameter. This gave us the date of the build, as well as indicating if it was a developer build (i.e. last component was zero)