如何从特定集合中的TFS2010项目中检索和保存任务(工作项)

时间:2011-08-02 01:37:05

标签: tfs2010

感谢前几天回答我之前提出的问题的帮助

How to retrieve TFS2010 projects from specific collection

现在,我认为上述问题将解决我遇到特定任务和阅读/保存任务的问题。但我无法找到解决方案。

我想要的是一个具有三个参数的功能 SaveWorkItem(CollectionID,ProjectID,WorkItemID)

然后我们可以更新项目中的工作项 - 集合。

任何帮助/指示都会受到高度赞赏。

感谢。

1 个答案:

答案 0 :(得分:2)

检索任务

public void RetrieveWorkItems()
    {
        var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFS:8080/TFS/DefaultCollection"));
        var workItemStore = tfs.GetService<WorkItemStore>();

        var wiqlQuery = String.Format( @"Select [State], [Title] From WorkItems Where [Work Item Type] = 'Task' Order By [State] Asc, [Changed Date] Desc"); ;


        WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
        foreach (WorkItem workItem in witCollection)
        {
            Console.WriteLine("ID: {0}", workItem.Id);
            Console.WriteLine("Title: {0}", workItem.Title);
        }
    }

输入任务

public void CrateTask()
    {
        var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFS:8080/TFS/DefaultCollection"));
        var workItemStore = tfs.GetService<WorkItemStore>();
        Project proj = workItemStore.Projects["ProjectName"];
        WorkItemType type = proj.WorkItemTypes["Task"];
        WorkItem workItem = new WorkItem(type);
        workItem.Title = "Task entered using API";
        workItem["Activity"] = "Configuration";
        workItem.Save();

    }