2016-12-21 27 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如何看待工作项目属性可能会有帮助。