使用 TFS API 返回新创建的 TFS 工作项 ID?
使用 TFS API,我可以创建 TFS 项目,没有问题。
我了解新创建的项目的项目 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
{
}
}
Using the TFS API, I am able to create a TFS item, no problem.
What would be the best way for me to know what the Item ID is for the newly created Item?
Thank you,
George
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
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦保存 userStory,ID 字段就会被填充。您应该能够只返回
userStory.Id
。As soon as you save userStory, the ID field will be populated. You should be able to just return
userStory.Id
.