We are writing a custom tool using TFS client APIs, to connect to TFS, to fetch work items for a project etc.
We are querying the work item store, using WIQL.
Given a fully qualified filename, what is the easiest way to get a list of work items that have change sets which contain the specified file?
I'm not sure that there is an easy way to do the query that you are requesting using the TFS API. I know that you definately cannot do it using WIQL. I think, using the API, you would have to iterate over all the work items - get the changeset links in them and then look in each changeset for the file path that you are after. This is obviously not much use.
You could get that data using the TFS Data Warehouse database however. This information will lag behind the live operational store information because the warehouse only gets updated periodically - but will allow you to track things by the folder/file dimension pretty easily.
This little code snippet will get you a collection of work items given a TFS server name and a project.. It also filters out work items in the deleted state.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace EngineTFSAutomation
{
class TFSHelper
{
static public WorkItemCollection QueryWorkItems(string server, string projectname)
{
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(server);
WorkItemStore workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
Project p = workItemStore.Projects[projectname];
string wiqlQuery = "Select * from Issue where [System.TeamProject] = '"+projectname+"'";
wiqlQuery += " and [System.State] <> 'Deleted'";
wiqlQuery+= " order by ID";
WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
return witCollection;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With