c#-4.0 – 使用TFS API返回新创建的TFS工作项ID?

前端之家收集整理的这篇文章主要介绍了c#-4.0 – 使用TFS API返回新创建的TFS工作项ID?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用TFS API,我可以创建一个TFS项,没问题.

什么是最好的方法,我知道什么项目ID是为新创建的项目?

谢谢,

乔治

  1. try
  2. {
  3. // Authenticate User Account
  4. NetworkCredential account = new NetworkCredential(USERNAME,PASSWORD,DOMAIN);
  5. // for user stories from the team project where the user story will be created.
  6. Uri collectionUri = new Uri(tfsURI);
  7. //TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri);
  8. TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(collectionUri,account);
  9. WorkItemStore workItemStore = tpc.GetService<WorkItemStore>();
  10. Project teamProject = workItemStore.Projects[info.TFSProjectName];
  11. WorkItemType workItemType = teamProject.WorkItemTypes[info.ItemType];
  12. // Create the work item.
  13. WorkItem userStory = new WorkItem(workItemType);
  14. userStory.Title = info.Title;
  15. userStory.Description = info.Description;
  16. userStory.AreaPath = info.AreaPath;
  17. userStory.IterationPath = info.IterationPath;
  18. userStory.Fields["Assigned To"].Value = info.AssignedTo;
  19. if (info.ItemType == "Task")
  20. {
  21. userStory.Fields["Discipline"].Value = info.Discipline;
  22. }
  23. else if (info.ItemType == "Bug")
  24. {
  25. userStory.Fields["Symptom"].Value = info.Symptom;
  26. userStory.Fields["Steps To Reproduce"].Value = info.StepsToReproduce;
  27. }
  28. else if (info.ItemType == "Change Request")
  29. {
  30. userStory.Fields["Justification"].Value = info.Justification;
  31. }
  32. // Save the new user story.
  33. userStory.Save();
  34. return true;
  35. }
  36. catch (Exception ex)
  37. {
  38. log.Error("Error Creating TFS Task.",ex);
  39. return false;
  40. }
  41. finally
  42. {
  43. }
  44. }

解决方法

保存userStory后,ID字段将被填充.你应该能够返回userStory.Id.

猜你在找的C#相关文章