如何使用 Visual Studio 宏运行 TFS 工作项查询 [英] How do I run a TFS Work Item Query with Visual Studio Macros

查看:7
本文介绍了如何使用 Visual Studio 宏运行 TFS 工作项查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 Vistual Studio 2008 宏来运行存储的 TFS 查询并显示结果.以前我创建了一个查询并将其命名为分配给我"以显示当前分配给我的所有工作项.而不是查看->团队资源管理器,单击,向下单击树到我的查询,然后双击分配给我"我想编写一个宏来自动执行这些步骤.

I'm trying to write a Vistual Studio 2008 macro to run a stored TFS query and display the results. Previously I've created a query and named it 'Assigned to Me' to display all the work items currently assigned to me. Instead of View->Team Explorer, click, click down the tree to My Queries then double click 'Assigned to me' I want to write a macro to automate these steps.

我想出的最好的是相当混乱:

The best I've come up with is the rather messy:

Sub TemporaryMacro()

    DTE.Windows.Item("{131369F2-062D-44A2-8671-91FF31EFB4F4}").Activate() 'Team Explorer
    DTE.ActiveWindow.Object.GetItem("tfsserverMyProjectWork ItemsMy QueriesAssigned to Me").Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ActiveWindow.Object.DoDefaultAction()
    DTE.Windows.Item("{131369F2-062D-44A2-8671-91FF31EFB4F4}").Close()
    DTE.Windows.Item("Assigned to Me [Results]").Activate()

End Sub

有没有更好的办法?

推荐答案

我编写了一个自定义 Windows 窗体应用程序,允许我运行我自己的动态查询,并创建新的或更新现有的工作项.

I've written a custom windows form application to allow me to run my own dynamic queries, and create new or update existing work items.

下面是我用来连接到我们的 TFS 2010 服务器、运行查询并返回结果的一段代码的简化版本.

Below is a simplified version of a section of code I use to connect to our TFS 2010 server, run a query and get the results back.

Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Imports System.Net
Imports System.Text.RegularExpressions
Imports System.Data.SqlTypes

Public Class DNATFSProxy
    Private _teamProjectCollection As TfsTeamProjectCollection
    Private _workItemStore As WorkItemStore
    Private _projectName As String
    Private _project As Project

    Public Sub Connect()
        _teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(New Uri(_uri))
        _workItemStore = New WorkItemStore(_teamProjectCollection)
        _project = _workItemStore.Projects(_projectName)
    End Sub

    Public Sub GetWorkItems(ByVal whereClause As String)
        If _workItemStore IsNot Nothing Then
            'Attempt to get the work items
            Dim query As String = String.Format("SELECT * FROM WorkItems WHERE {0}", whereClause)

            Dim workItemCollection As WorkItemCollection = _workItemStore.Query(query)

            'Iterate through each work item
            For Each workItem As WorkItem In workItemCollection

                'Insert your custom code here
                Dim title As String = workItem.Title.ToString()

                'You can also update the work item in TFS
                workItem.Title = "New title"
                workItem.Save()
            Next
        End If
    End Sub

Public Property URI() As String
    Get
        Return _uri
    End Get
    Set(ByVal value As String)
        _uri = value
    End Set
End Property

Public Property Project() As String
    Get
        Return _projectName
    End Get
    Set(ByVal value As String)
        _projectName = value
    End Set
End Property

End Class

然后您可以按如下方式调用此代理:

You can then call this proxy as follows:

   Dim proxy As New DNATFSProxy()
   proxy.URI = "http://tfs:8080/tfs/DefaultCollection"
   proxy.Project = "Your Project Name"
   proxy.Connect()
   proxy.GetWorkItems("Insert your query here")

我希望这会有所帮助!

这篇关于如何使用 Visual Studio 宏运行 TFS 工作项查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆