In Team Foundation Server 2010 web access is installed by default. Therefore you can now happily create links to web access resources and know that there is somewhere that you can point a web browser to to find more information. However what is less well known is that there is a handy service available in the TFS 2010 object model to help you create the links – the TswaClientHyperlinkService.
Take a quick look at the MSDN documentation for more information, but a quick look at the methods available in IntelliSense shows you some very useful methods including:
- GetAnnotateSourceControlItemUrl – Annotate a file in version control
- GetChangesetDetailsUrl – Show the details for a particular changeset including comments and all the files changes along with links to do comparisons of individual files etc.
- GetDifferenceSourceControlItemsUrl – Show the results of a diff between two files in version control
- GetHistorySourceControlItemUrl – Show the history for a file in version control
- GetHomeUrl – Get a link to the web access application for the server you are talking to
- GetShelvesetDetailsUrl – Show the shelveset details including links to be able to compare the files in that shelveset. Great for code reviews.
- GetSourceExplorerUrl – Show the passed path in source control explorer
- GetViewBuildDetailsUrl – Show the build report for the passed in build detail.
- GetViewSourceControlItemUrl – Show the passed item from version control.
- GetWorkItemEditorUrl – Show the work item
- GetWorkItemQueryResultsUrl – Run the passed stored query on the server and show the results
Using the link service is very easy if you are used to calling other TFS services in code. For example:
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(projectCollectionUrl));
TswaClientHyperlinkService service = tfs.GetService<TswaClientHyperlinkService>();
if (service != null)
{
// View Changeset
int changesetId = 1;
Uri viewChangesetUrl = service.GetChangesetDetailsUrl(changesetId);
Console.WriteLine("Changeset " + changesetId + ": " + viewChangesetUrl.AbsoluteUri);
// View annotate on a file
Uri annotateFileUrl = service.GetAnnotateSourceControlItemUrl("$/path/to/file/myfile.txt",
VersionSpec.Latest.ToString());
Console.WriteLine("Annotate: {0}", annotateFileUrl.AbsoluteUri);
}