0

我正在寻找一个很好的例子来开始使用 TFS 2010 集合、项目和工作项。

我可以使用以下代码遍历集合和项目(感谢原始编码器)

Dim tfsServer As String = "http://test.domain.com:8080/tfs"
    tfsServer = tfsServer.Trim()
    Dim tfsUri As Uri
    tfsUri = New Uri(tfsServer)
    Dim configurationServer As New TfsConfigurationServer(tfsUri)
    configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri)

    ' Get the catalog of team project collections
    Dim collectionNodes As ReadOnlyCollection(Of CatalogNode)
    Dim gVar As Guid() = New Guid() {CatalogResourceTypes.ProjectCollection}
    collectionNodes = configurationServer.CatalogNode.QueryChildren(gVar, False, CatalogQueryOptions.None)

    Dim strName As New StringBuilder
    Dim strCollection As New StringBuilder

    For Each collectionNode In collectionNodes
        Dim collectionId As Guid = New Guid(collectionNode.Resource.Properties("InstanceID"))
        strName.Length = 0
        Dim teamProjectCollection As New TfsTeamProjectCollection(tfsUri)
        teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId)
        Response.Write("Collection:" & teamProjectCollection.Name & "<br/>")

        ' Get a catalog of team projects for the collection
        Dim hVar As Guid() = New Guid() {CatalogResourceTypes.TeamProject}

        Dim projectNodes As ReadOnlyCollection(Of CatalogNode)
        projectNodes = collectionNode.QueryChildren(hVar, False, CatalogQueryOptions.None)

        ' List the team projects in the collection
        For Each projectNode In projectNodes
            strName.AppendLine(projectNode.Resource.DisplayName & "<br>")
            'System.Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName)
        Next

        Response.Write(strName.ToString())

    Next

我想从集合中读取特定项目并遍历工作项(任务、错误、问题等)。任何帮助将不胜感激。

谢谢。

4

1 回答 1

0

您可以在teamProjectCollection- 级别运行您喜欢的任何查询:

        WorkItemStore workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
        WorkItemCollection queryResults = workItemStore.Query(query);

        foreach (WorkItem workitem in queryResults)
        {
            Console.WriteLine(workitem.Title);             
        } 

现在您只需将query- 字符串表述为能够为您提供所需内容的东西。

查询类似于 WIQL。这个非常基本的可以为您提供 TeamProject 中的所有工作项:

SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItems WHERE [System.TeamProject] = @project


@project在我们的例子中是projectNode.Resource.DisplayName

(您可以使用“另存为”将您在 TFS 中以图形方式设置的任何查询保存为 *.wiq 文件,然后以编程方式使用它的内容)

于 2011-07-27T09:05:50.660 回答