且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取链接的“版本化项目"?来自TFS

更新时间:2023-01-14 23:24:13

工作项查询只能显示WorkItemLinkType链接.要获取其他类型的链接(即源代码管理中的文件),您需要浏览WorkItem对象本身中的链接列表.这是一段代码,它将为您提供链接到工作项的文件的工件:

Work item queries can only show WorkItemLinkType links. To get links of other types (i.e. files in source control), you need to go through the list of links in the WorkItem object itself. Here's a snippet of code that will get you the artifact of the file linked to the work item:

TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
    new Uri("http://<server>:8080/tfs/<collection>"));

WorkItemStore wiStore = tpc.GetService<WorkItemStore>();

VersionControlServer vc = tpc.GetService<VersionControlServer>();

WorkItem task = wiStore.GetWorkItem(<work item with a linked file>);

var externalLinks = task.Links.OfType<ExternalLink>();

foreach (var link in externalLinks)
{
    XmlDocument artifact = vc.ArtifactProvider.GetArtifactDocument(new Uri(link.LinkedArtifactUri));
}

XML文档包含使用GetItem()方法从VersionControlServer获取正确文件版本所需的所有必要信息.

The XML document contains all necessary information needed to grab the correct file version from the VersionControlServer using the GetItem() method.