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

前端之家收集整理的这篇文章主要介绍了c#-4.0 – 使用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
        {
        }
    }

解决方法

保存userStory后,ID字段将被填充.你应该能够返回userStory.Id.
原文链接:https://www.f2er.com/csharp/93474.html

猜你在找的C#相关文章