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

发布于 2024-09-26 02:29:37 字数 2019 浏览 3 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沦落红尘 2024-10-03 02:29:37

一旦保存 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文