如何根据System.ID选择TFS历史记录

时间:2017-03-29 20:49:46

标签: powershell tfs

下面的脚本允许我从TFS获取变更集历史记录。如何根据PBI numberSystem.ID

获取历史记录
Get-TfsItemHistory $locationToSearch -Recurse -Version $dateRange | 
Sort CreationDate | Select ChangeSetId,Committer,Comment,CreationDate |  Format-Table ChangeSetId,CreationDate,Committer,Comment -Auto -Wrap  | 
out-file "C:\full.txt"

1 个答案:

答案 0 :(得分:0)

Get-TfsItemHistorycommandlet in tfspowertools。它无法得到你想要的东西。您可以使用TFS Client API来实现它,请参考AlexanderM's answer

中的代码示例
private static void GetChangesForWorkItem()
{
    var configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(new Uri(@"http://myserver:8080/tfs"));
    var tpcService = configurationServer.GetService<ITeamProjectCollectionService>();
    var collectionNodes = configurationServer.CatalogNode.QueryChildren(
           new[] { CatalogResourceTypes.ProjectCollection },
           false, CatalogQueryOptions.None);

    var collectionNode = collectionNodes.First(x => x.Resource.DisplayName == "<collection name>");

    // Use the InstanceId property to get the team project collection
    Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
    TfsTeamProjectCollection collection = configurationServer.GetTeamProjectCollection(collectionId);
    var vcs = collection.GetService<VersionControlServer>();
    var store = new WorkItemStore(collection);
    var workItems = new List<WorkItem>()
    {
        store.GetWorkItem(1123),
        store.GetWorkItem(1145),
    };

    var associatedChangesets = new List<Changeset>();

    foreach (var workItem in workItems)
    {
        foreach (var link in workItem.Links) 
        {
            if((link==null) || !(link is ExternalLink))
            continue;

            string externalLink = ((ExternalLink)link).LinkedArtifactUri;
            var artifact =LinkingUtilities.DecodeUri(externalLink);

            if (artifact.ArtifactType == "Changeset")
                associatedChangesets.Add(vcs.ArtifactProvider.GetChangeset(new Uri(externalLink)));
        }
    }

    Console.WriteLine(associatedChangesets.Select(x=>x.ChangesetId).OrderBy(x => x));
}

另一种方法是使用TFS RSET API,然后用rel ==“ArtifactLink”过滤掉“relations”数组

   Get  https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/workitems?ids=297,299,300&$expand=all&api-version=1.0