如何在创建UserStory时以编程方式在TFS中的“AssignedTo”字段中设置值?

时间:2015-03-19 10:58:46

标签: c# .net c#-4.0 tfs tfs-sdk

代码:

//创建用户素材

    var collectionUri = new Uri(txtTFS.Text);
    var tpc = new TfsTeamProjectCollection(collectionUri);
    var workItemStore = tpc.GetService<WorkItemStore>();
    var teamProject = workItemStore.Projects[txtSelectedProject.Text];

    var typeWorkItem = ConfigurationManager.AppSettings["WorkItemType"];
    var workItemType = teamProject.WorkItemTypes[typeWorkItem];

    var userStory = new WorkItem(workItemType)
    {
        Title = "Test Title",
        Description = "Test Description",
        IterationPath = "xx\\yy\\zz",
        AreaPath = "xxx\\yyy\\zzz",
        State = "New",
        // "AssignedTo" field not populated here...
    };

    // Save the new user story.
    userStory.Save();

如何在创建"AssignedTo"时以编程方式在TFS UserStory字段中设置值?

1 个答案:

答案 0 :(得分:2)

只有每个工作项类型上的字段在WorkItem类上都有自己的属性。

您应该使用WorkItem.Fields属性来访问任何不属性的字段。

userStory.Fields["System.AssignedTo"].Value = "JJJ";

您无法在对象intialiser语法中使用带有索引器的属性,因此您必须在.Save();

之前使用新行