2016-12-21 26 views
2

我正在嘗試使用C#代碼創建一個tfs任務。我可以用下面的代碼添加任務。 但我無法通過此添加assignedto,關鍵字,優先等。我沒有在workItemType對象中找到相關的屬性。添加具有優先級的TFS任務,分配給使用C#

我試過字段[「關鍵字」]等,但它沒有爲我工作。任何指針請

private static readonly Uri TfsServer = new Uri("my tfs url"); 
     static readonly TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(TfsServer); 
     static readonly WorkItemStore workItemStore = tpc.GetService<WorkItemStore>(); 
     static readonly Project teamProject = workItemStore.Projects["my project name"]; 
     static readonly WorkItemType workItemType = teamProject.WorkItemTypes["Task"]; 

WorkItem tfsTask = new WorkItem(workItemType) 
      { 
       Title = "Test Title", 
       //assignedto, 
       State = "Proposed", 
       //substatus ="Not Started", 
       AreaPath = @"my path", 
       IterationPath = @"my iteration path", 
       //Keywords ="my keyword", 
       //prioity=3 

       Description = "newVcDescription" 
      }; 

      tfsTask.Save(); 

回答

2

當您從new WorkItem(workitemType){}設定工作項字段的值,你只能爲通過智能感知提供這些字段的值: enter image description here

對於其他領域,你可以這樣設置值:

tfsTask.Fields["Priority"].Value = "4"; 
tfsTask.Fields["Assigned To"].Value = "XXX"; 
tfsTask.Tags = "tag1;tag2"; 
tfsTask.Save(); 
2

因此,不是所有的標準屬性的tfs可以這樣調用。在C#中不是100%確定的,但在PowerShell中,我將不得不這樣做。

$proj = $ws.Projects["Scrum Test"] 
$ProductBacklogWorkItem=$proj.WorkItemTypes["Product Backlog Item"] 
$pbi=$ProductBacklogWorkItem.NewWorkItem() 


// stadard attribute 
$pbi.Description = $SRLongDescription 

// nonstandard 
$pbi["Assigned to"] = $SROwner 

// custom elements 
$pbi["Custom.CD.ExternalReferenceID"] = $SRTicketId 

我知道它有不同的調用方式,但認爲了解TFS如何看待工作項目屬性可能會有幫助。