TFS API - 如何从特定团队项目获取工作项
我正在尝试查询主 TfsTeamProjectCollection
中的单个团队项目,该项目总共包含 194 个团队项目。我确切地知道如何通过 Id 从 WorkItemStore
获取 WorkItem
。事实是,通过执行此操作,API 会搜索集合中的所有 项目,并且查询大约需要一分钟。这太慢了,必须有一种方法可以直接从单个团队项目查询工作项?这是我的代码:
private Uri collectionUri;
private TfsTeamProjectCollection projectCollection;
private WorkItemStore workItemStore;
public Project GetTeamProject()
{
projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(collectionUri);
workItemStore = projectCollection.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects[TFS_PROJECT_KEY];
return teamProject;
}
现在我有了我感兴趣的团队项目,如何通过 ID 查询工作项或仅获取该项目中的所有工作项?
I am trying to query a single team project in the main TfsTeamProjectCollection
which contains 194 Team Projects in total. I know exactly how to get a WorkItem
by Id from a WorkItemStore
. The thing is, that by doing this, the API searches in ALL of the projects in the collection and the query takes about a minute. This is way too slow, there must be a way to query work items directly from a single team project ? Here is the code I have:
private Uri collectionUri;
private TfsTeamProjectCollection projectCollection;
private WorkItemStore workItemStore;
public Project GetTeamProject()
{
projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(collectionUri);
workItemStore = projectCollection.GetService<WorkItemStore>();
Project teamProject = workItemStore.Projects[TFS_PROJECT_KEY];
return teamProject;
}
Now that I have the Team Project I'm interested in, how can I query for work items by ID or just get all work items in this project ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试类似的方法来获取
teamProject
中的所有 WI:并获取特定的 WorkItem ID:
You could try something like this for getting all WIs within
teamProject
:And this to get a specific WorkItem ID:
使用查询查找工作项可能是最有效的您感兴趣。您可以将Where project = '@Project' 添加到查询中,以将范围限制为仅该项目。通过首先调用 BeginQuery,然后调用 EndQuery,您将获得仅包含您要查找的项目的工作项集合。
获取所需 wql 查询的最简单方法是在团队资源管理器中创建查询,然后使用文件->另存为(在编辑模式下)将其保存到文件。在记事本中打开该文件以从其中复制查询。
或者,您可以使用 WorkItemStore .直接使用查询方法来实现同样的事情。
It's probably most efficient to use a query to find the workitems you're interested in. You can add a Where project = '@Project' to the query to limit the scope to just that project. By first calling BeginQuery and then EndQuery you'll get a workitem collection for just the items you were looking for.
The easiest way to get the required wql query is to create a query in Team Explorer, then use file->save as (in edit mode) to save it to file. Open that file in Notepad to copy the query out of there.
Alternatively you can use the WorkItemStore.Query method directly to achieve the same thing.