代码之家  ›  专栏  ›  技术社区  ›  amazedsaint

TFS客户端API-查询以获取链接到特定文件的工作项?

  •  5
  • amazedsaint  · 技术社区  · 15 年前

    我们正在使用TFS客户端API编写一个定制工具,用于连接TFS,获取项目的工作项等。


    我们正在使用WIQL查询工作项存储。

    4 回复  |  直到 13 年前
        1
  •  4
  •   Martin Woodward    15 年前

        2
  •  3
  •   Ivan Bohannon    13 年前

    这个小代码片段将为您提供一个TFS服务器名称和一个项目的工作项集合。。它还过滤掉处于已删除状态的工作项。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.WorkItemTracking.Client;
    
        namespace EngineTFSAutomation
        {
            class TFSHelper
            {
                static public WorkItemCollection QueryWorkItems(string server, string projectname)
                {
                    TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(server);
                    WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
                    Project p = workItemStore.Projects[projectname];
                    string wiqlQuery = "Select * from Issue where [System.TeamProject] = '"+projectname+"'";
                    wiqlQuery += " and [System.State] <> 'Deleted'";
                    wiqlQuery+= " order by ID";
                    WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
                    return witCollection;
                }
            }
        }
    
        3
  •  1
  •   DevT    11 年前

    对于

        Uri tfsUri = new Uri("http://xxx.xx.xx.xxx:8080/tfs2012");
        TfsConfigurationServer configurationServer =TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);                  
        ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(new[] {CatalogResourceTypes.ProjectCollection },false,CatalogQueryOptions.None);   
    
        foreach (CatalogNode collectionNode in collectionNodes)
        {
            // Use the InstanceId property to get the team project collection
            Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
    
            WorkItemStore workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
    
            string query = "SELECT [System.Id] FROM WorkItems where [Assigned to]=@Me";
            WorkItemCollection queryResults = workItemStore.Query(query);
    
        }
    
        4
  •  0
  •   ASout    9 年前

    对于TFS 2013,以下代码用于访问TFS项目信息:

    var tfsUri = new Uri("http://tfs.xxx.xxx.com:8080/tfs/myCollection");
    var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
    tfs.EnsureAuthenticated();
    var iis = tfs.GetService<Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore>();
    // here access to a particular Project with its name
    var uriWithGuid = iis.Projects["My project name"].Uri;