Search code examples
tfstfs-sdk

Get the Installed TFS Server version from TFS API (Is it 2010 or 2012?)


I have a WCF service that calls both TFS 2010 and 2012 instances. I'm looking for a way to distinguish between 2010 and 2012 in the API, but there doesn't seem to be a GetServerVersion() or similar API.

The reason is that there were slight changes in the way that 2010 and 2012 handle work item links:

  • Work Item Links in 2010: http://TFSUri/web/wi.aspx?id=WorkItemID

  • Work Item Links in 2012: http://TFSUri/TFSProject/_workitems/edit/WorkItemID

Worst case I can make people select their version, but I'd really prefer to automatically distinguish 2010 vs. 2012 if possible.


Solution

  • You can use the IBuildServer interface from Build.Client to get the version of the server.

    TeamFoundationServer tfs = new TeamFoundationServer(@"http://yourtfs:8080/tfs");
    IBuildServer tfsb = tfs.GetService<IBuildServer>();
    Console.WriteLine(tfsb.BuildServerVersion); //v3 for 2010 and v4 for 2012