How to map a TFS item url to something viewable

Gone Coding picture Gone Coding · Jun 24, 2011 · Viewed 8.4k times · Source

We are programmatically generating deployment emails, based on the history of changesets and associated workitems since the last deployed build. They look a bit like the build summary info inside Visual Studio (but with many builds combined).

There appear to be useful URLs in the data (like vstfs:///VersionControl/Changeset/205151), but being new to the TFS SDK I do not if/how this maps to a viewable item (e.g. http://tfsserver:port/somepath/...). The build summary links inside Visual Studio are clickable, but are they VS-only links?

If possible we want to include links in the email that open the related item (in a browser?), so I guess I need to know if TFS paths are web-browsable and if so, how?

Suggestions welcomed. Thanks.

Answer

Tarun Arora picture Tarun Arora · Jun 25, 2011

This is the uRl i have been using to access work items,

=> http://ServerName:PortNumber/tfs/web/wi.aspx?id=xxidxx

Edit The format i have specified does work with TFS 2010. It basically generates the path to the work item in Web view. Clicking on this opens the work item in the web view.

As an alternate, you could get a navigatable URL programmatically as well.

var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFSURL"));
var versionControl = tfs.GetService<ICommonStructureService>();

var projects = versionControl.ListAllProjects();

var myService = tfs.GetService<TswaClientHyperlinkService>();

var myUrl = myService.GetChangesetDetailsUrl(21);

So, the service "TswaClientHyperlinkService" is microsofts TFS hyperlink service. This will generate the url formats for Absolute path, relative path, Path and Query, blah blah.

HTH,

Cheers, Tarun

PS - I hate to be wrong!!! hahaha... enter image description here

EDIT And since in your case you have the URI available and you already are using the TFS API, these two lines of code would do the trick.

var testManagementService = tfs.GetService<ILinking>();
var testControllers = testManagementService.GetArtifactUrl(@"vstfs:///VersionControl/Changeset/205151");

This will generate, https://ServerName:PortNumber/defaultcollection/VersionControl/Changeset.aspx?artifactMoniker=205151

HTH,

Cheers, Tarun