Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changeset Number into Version Info with hosted TFS

We're using Team Foundation Service instead of a local TFS. Our solution was created on Visual Studio 2012. My problem is now that we want all assemblies to have the same version number (this part is already solved by using a CommonAssemblyInfo.cs that is linked into all projects). The issue I'm facing right now is that we need the tfs changeset number at the last digit of the assembly version (e.g. 1.0.0.4711 where 4711 is the changeset number). I've found several examples, but none of them worked for me. And yes, I especially searched here on stackoverflow a lot.

I also have to admit that I've never looked into the MSBuild scripts...

Can anyone please give me a hint on how to accomplish this? Is it for example possible to use the MSBuild Extension Pack on Team Foundation Service (not local TFS) and if, how to do that?

As always, time is my worst enemy...

like image 465
AlexK Avatar asked Feb 05 '13 14:02

AlexK


1 Answers

Note that from 2010 Tfs employs Windows workflow for building the package the workflow calls msbuild for compiling the projects only - while its possible to pass changeset this way to msbuild its rather more hops. Following deals with your problem, however the linked solution is more complex that needed: Can assembly version been automatically updated with each TFS 2010 Build?

This is one of best series of tutorials on the custom build activities, the author is on stack as well i believe, one specificly about versioning http://www.ewaldhofman.nl/post/2010/05/13/Customize-Team-Build-2010-e28093-Part-5-Increase-AssemblyVersion.aspx

In short you need a custom activity to run before compilation on source files, find all CommonAssemblyInfo.cs files, feed this list to your custom activity, it modifies the values inside with passed value of full version number or only the changeset and optionaly check in the change (probably not since your changeset will be out of sync then).

You can also take a look at https://tfsbuildextensions.codeplex.com/ set of activities there is TfsVersion activity among them, at the very least it will provide examples.

Functionality need for this should be available through Team Explorer and source control - The Custom activity assemblies and build templates usually are located in folder in your team project root - the location of this folder is defined for build controller you can change this through team explorer build section.

Changeset is available from value BuildDetail.SourceGetVersion, not sure if this was fixed/changed in 2012 however there were 2 issues about this value in 2010

  1. Its doesnt respect GetVersion override in default build template - you will manualy need to update if override is used
  2. When running latest build (no override) it will get the last changeset number from tfs - depending on your branches this may not be the same as 'last' changeset for the branch of build. You will either have to live with this, provide overrides for each build or implement activity that checks branch history for last changeset value and overrides it again.

It should be noted that GetVersion should be able to accept any sourcespec version - changeset, date, label etc. I havent played around with this enough to provide more details to you.

like image 59
drk Avatar answered Oct 05 '22 19:10

drk