How to map a TFS item url to something viewable

2019-02-17 09:01发布

问题:

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.

回答1:

The following seems to be the standard url for accessing work items

http://TFS_Name:port_number/WorkItemTracking/Workitem.aspx?artifactMoniker=work_Item_Id



回答2:

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...

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



回答3:

The vstfs links are called "artifact IDs" and are internal data to TFS that is expected to only be consumed by a TFS client. A TFS client will parse that data and determine how to display that data. For a changeset link like you provide, the rich clients will open up a dialog with the changeset details. A web client would translate that link into a URI. And the various TFS libraries are able to provide you more data on this artifact using that ID.

If you wanted to create your own link to TFS Web Access, the strictly proper way to do this is to query some information on the server. Once you have a TswaClientHyperlinkService, you can query for the Web Access URIs for various services, such as view a changeset or view a work item. Some examples are shown on Martin Woodward's blog.



回答4:

In TFS2012, an additional pcguid URL parameter needs to be present. Here's the new format, extending the good solution given by @TarunArora:

http://ServerName:PortNumber/tfs/web/wi.aspx?pcguid=xxguidxx&id=xxidxx

This blog post describes how to find the pcguid via Visual Studio.

However, if like me you're attempting to use TFS without Visual Studio installed (don't ask!), here's an alternative using the browser-based TFS interface:

  1. Go to "Open Issues"
  2. Click on the button that looks like an envelope ("Send query as an email") in the top right of the work item pane.
  3. Right-click on one of the links in the email and copy the link location
  4. Cancel out of the email without sending it.
  5. Paste link location into a text editor and extract the pcguid value.