簡體   English   中英

TFS 客戶端 API - 查詢以獲取鏈接到特定文件的工作項?

[英]TFS Client API - Query to get work items linked to a specific file?

我們正在使用 TFS 客戶端 API 編寫自定義工具,以連接到 TFS,獲取項目的工作項等。


我們正在使用 WIQL 查詢工作項存儲。

給定一個完全限定的文件名,獲取具有包含指定文件的更改集的工作項列表的最簡單方法是什么?

我不確定是否有一種簡單的方法可以使用 TFS API 執行您請求的查詢。 我知道你肯定不能使用 WIQL 來做到這一點。 我認為,使用 API,您將不得不遍歷所有工作項 - 獲取其中的變更集鏈接,然后在每個變更集中查找您所追求的文件路徑。 這顯然沒有多大用處。

但是,您可以使用 TFS 數據倉庫數據庫獲取該數據。 此信息將落后於實時運營商店信息,因為倉庫只會定期更新 - 但可以讓您輕松地按文件夾/文件維度跟蹤事物。

這個小代碼片段將為您提供一個給定 TFS 服務器名稱和一個項目的工作項集合。它還過濾掉已刪除的 state 中的工作項。

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;
            }
        }
    }

適用於TFS 2012

    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);

    }

對於 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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM