2011-02-07 65 views
5

我們有一個自定義構建過程(不使用MS構建),並且在此過程中,我將一個「假」構建添加到全局構建列表。我這樣做的原因是,您可以選擇給定工作項目的構建(在構建中找到)。我們有一個自定義字段,包含構建,用於顯示該工作項固定在哪個構建中。我無法確定如何以編程方式更新此字段。這個想法是,我將有一個小應用程序,它會在構建過程中調用這些應用程序,查找自上次構建以來的所有工作項目,然後更新這些工作項目的字段。有任何想法嗎?如何以編程方式更新自定義TFS字段

+0

您可以更具體地瞭解全局構建列表部分。您是否使用自定義構建模板(在Windows Workflow Foundation中)?你是否添加到該模板中的變量或參數? – LWoodyiii 2011-02-07 18:21:37

+0

對不起,我正在使用TFS中的全局列表。我沒有使用構建模板,我們正在使用名爲Automated Build Studio的產品作爲實際構建本身。我正打算編寫一個獨立的應用程序來從ABS呼叫此功能。 – Nick 2011-02-07 18:37:24

回答

13

像這樣的東西應該爲你工作:

public void UpdateTFSValue(string tfsServerUrl, string fieldToUpdate, 
    string valueToUpdateTo, int workItemID) 
{ 
    // Connect to the TFS Server 
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsUri)); 
    // Connect to the store of work items. 
    _store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); 
    // Grab the work item we want to update 
    WorkItem workItem = _store.GetWorkItem(workItemId); 
    // Open it up for editing. (Sometimes PartialOpen() works too and takes less time.) 
    workItem.Open(); 
    // Update the field. 
    workItem.Fields[fieldToUpdate] = valueToUpdateTo; 
    // Save your changes. If there is a constraint on the field and your value does not 
    // meet it then this save will fail. (Throw an exception.) I leave that to you to 
    // deal with as you see fit. 
    workItem.Save();  
} 

調用此的一個例子是:

UpdateTFSValue("http://tfs2010dev:8080/tfs", "Integration Build", "Build Name", 1234); 

變量fieldToUpdate應該是實地,而不是refname的名稱(即Integration Build,而不是Microsoft.VSTS.Build.IntegrationBuild

你可能會使用PartialOpen(),但我不確定。

您可能需要將Microsoft.TeamFoundation.Client添加到您的項目中。 (也許Microsoft.TeamFoundation.Common

4

這種情況已經改變了2012 TFS,basicly必須添加workItem.Fields [fieldToUpdate] .value的

更新的版本是什麼@Vaccano寫道。

public void UpdateTFSValue(string tfsServerUrl, string fieldToUpdate, 
    string valueToUpdateTo, int workItemID) 
{ 
    // Connect to the TFS Server 
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(tfsUri)); 
    // Connect to the store of work items. 
    _store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore)); 
    // Grab the work item we want to update 
    WorkItem workItem = _store.GetWorkItem(workItemId); 
    // Open it up for editing. (Sometimes PartialOpen() works too and takes less time.) 
    workItem.Open(); 
    // Update the field. 
    workItem.Fields[fieldToUpdate].Value = valueToUpdateTo; 
    // Save your changes. If there is a constraint on the field and your value does not 
    // meet it then this save will fail. (Throw an exception.) I leave that to you to 
    // deal with as you see fit. 
    workItem.Save();  
} 
相關問題