Syncing the build number and assembly version numbers in a TFS build when using the TFSVersion activity

I was asked recently if it was possible to make the TFS build number the same format as the assembly build number when you are using the TFSVersion community extension. The answer is yes and no; the issue is that the build drop location in the standard build process template is create before any files are got into the workspace from source control. So at this point you don’t have new version number, a bit of a problem.

A detailed description of one approach to this general problem can be found in Ewald Hofman’s blog on the subject, but to use this technique you end up creating another custom activity to update the build number using your own macro expansion. Also there will be some major workflow changes to make sure directories are created with the correct names.

I was looking for a simpler (lazier) solution when using the TFSVersion activity and the one I came up with to just update the build name, and do it after the drop directory was created. So that I did not end up with two completely different names for the drop folder and build I just append the version number to the existing build number. This is done by re-running the Update Build Number activity. I added this new activity to example workflow logic from the TFSVersion documentation, ending up with something like

image

where the Update Build Number has the following properties

image

So we just append the newly generated version number to the existing build number.

string.Format("{0} ({1})", BuildDetail.BuildNumber , VersionNumber)

Note you can’t use the BuildNumberFormat.in this string format as this string contains the $(BuildDefinitionName)_$(Date:yyyyMMdd)$(Rev:.r) text that via macro expansion is used to generate the build number. The problems if this expansion if used in this string format you get the error

The revision number $(Rev:.r) is allowed to occur only at the end of the format string.

So it is easier to use the previously generated build number.

This also has the effect that drop folder retains the original name but all the reports contain the old folder name with the generated build number in brackets, and the Open Drop Folder link still works

image

I reasonable compromise I think, not too much change from a standard template.