2

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.

2 Answers 2

3

Providing I understand your use-case the alternative, and arguably better way than defining a URL pattern for a given TFS version, is to use the TswaClientHyperlinkService to generate your URLs. You can use this API class to generate a URL for a given work item Id for example, through the GetWorkItemEditorUrl method; e.g. using the v11 client dlls :

var collection = new TfsTeamProjectCollection(
                     new Uri("http://<tfsuri>/tfs/<collection>/"));

var hyperlinkService = collection.GetService<TswaClientHyperlinkService>();
var link = hyperlinkService.GetWorkItemEditorUrl(<workitemid>);

// against TFS 2012:
// var link: 
//  http://<tfsuri>/tfs/web/wi.aspx?pcguid=<guid>&id=<workitemid>
// redirects to 
//  http://<tfsuri>/tfs/<collection>/<project>/_workitems#_a=edit&id=<workitemid>

I haven't got a TFS 2010 instance to test this against, but fingers crossed this would be transparent across calls to different versions.


All that said, this question has been asked before. But the method in the link of the accepted answer derives different versions by identifying functionality introduced at each release. This is applicable to differentiating 2005, 2008 and 2010. I don't know if the same approach can be used to differentiate 2010 and 2012 (or if a more palatable API method now exists).

1
  • Thanks! I started using this for hyperlinks and was able to make it work for both 2010 and 2012.
    – ChrisG
    Feb 28, 2013 at 23:14
1

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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.