2010-09-29 96 views
9

使用TFS API,我可以創建一個TFS項目,沒有問題。使用TFS API返回新創建的TFS工作項ID?

什麼是最好的方式來知道什麼Item ID是爲新創建的項目?

謝謝

喬治

 try 
     { 
      // Authenticate User Account 
      NetworkCredential account = new NetworkCredential(USERNAME, PASSWORD, DOMAIN); 
      // for user stories from the team project where the user story will be created. 
      Uri collectionUri = new Uri(tfsURI); 
      //TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri); 
      TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri, account); 
      WorkItemStore workItemStore = tpc.GetService<WorkItemStore>(); 
      Project teamProject = workItemStore.Projects[info.TFSProjectName]; 
      WorkItemType workItemType = teamProject.WorkItemTypes[info.ItemType]; 
      // Create the work item. 
      WorkItem userStory = new WorkItem(workItemType); 
      userStory.Title = info.Title; 
      userStory.Description = info.Description; 
      userStory.AreaPath = info.AreaPath; 
      userStory.IterationPath = info.IterationPath; 
      userStory.Fields["Assigned To"].Value = info.AssignedTo; 
      if (info.ItemType == "Task") 
      { 
       userStory.Fields["Discipline"].Value = info.Discipline; 
      } 
      else if (info.ItemType == "Bug") 
      { 
       userStory.Fields["Symptom"].Value = info.Symptom; 
       userStory.Fields["Steps To Reproduce"].Value = info.StepsToReproduce; 
      } 
      else if (info.ItemType == "Change Request") 
      { 
       userStory.Fields["Justification"].Value = info.Justification; 
      } 
      // Save the new user story. 
      userStory.Save(); 
      return true; 
     } 
     catch (Exception ex) 
     { 
      log.Error("Error Creating TFS Task.", ex); 
      return false; 
     } 
     finally 
     { 
     } 
    } 

回答

15

只要你保存用戶故事,ID字段將被填充。你應該能夠返回userStory.Id

+1

Robaticus,謝謝你的回答。它工作完美。 :) – ElMatador 2010-10-21 23:47:48

相關問題