使用TFS API返回新创建的TFS工作项ID?

9
使用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
        {
        }
    }
1个回答

15
一旦您保存用户故事,ID字段将被填充。您只需返回userStory.Id即可。

1
Robaticus,谢谢你的回答。它完美地解决了我的问题。 :) - ElMatador

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接