Question

I want to use the VersionTask from the MSBuild Community Tasks to set the Revision calculation type. However, I am having difficulty understanding how to actually wire up the task within my csproj file.

The project has an AssemblyInfo.cs which has the following attribute defined:

[assembly: AssemblyVersion("3.2.5.*")]

What I want to do is over-ride the generation of the Revision number handling with my own custom handling.

I have put the customised Version task into the csproj file as follows:

<UsingTask TaskName="MyCo.Build.Tasks.Version" AssemblyFile="$(SolutionDir)\..\Build\.build\MyCo.Build.Tasks.dll" />

The actual task is then called as follows:

  <Target Name="BeforeBuild">
<Message Text="Setting Revision Number to $(BuildNumber)" />
<MyCo.Build.Tasks.Version RevisionType="BuildServerNumber" Revision="$(BuildNumber)" /></Target>

I can see the target BeforeBuild being called because of the Message Task but the exe file still has the standard generated numbering as follows: File Version : 3.2.5.27547

I was expecting something like 3.2.5.111 (the build number passed into MSBuild as a parameter).

As the Version task is overriding the default handling of the '*' value for Revision I don't believe it is necessary to actually modify the AssemblyInfo.cs file.

Do I need to pass the output value from the Version task into an MSBuild parameter? Do I actually need to use the AssemblyVersion task to update the values in the file?

Obviously I am trying to avoid having to change the AssemblyInfo.cs, I just want to override the Version number handling.

Can someone advise please?

EDIT: I just found the following example of usage in the chm file from the installer which partly answers my question.

           <Version BuildType="Automatic" RevisionType="Automatic" Major="1" Minor="3" >
            <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)"/>

However, when I run the build I can output the generated Assembly Version in a Message task but the exe file still has the default Revision as before

Was it helpful?

Solution

I got a resolution to this here: How to override the revision number

In the end I had to actually update the AssemblyInfo file for each project during the build. So on the build server (TeamCity) I placed the code I needed in the Microsoft.Common.targets file so that it wasn't required in each project ad then passed the release number and TeamCity build number to each build task.

OTHER TIPS

The Revision is the number of days since 1/1/2000 when you set it to Automatic - you can supply your own "StartDate" if you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top