We are writing a custom tool using the TFS client APIs, for connecting to TFS, for extracting work items for a project, etc.
We request work item storage using WIQL.
Given the full file name, what is the easiest way to get a list of work items that have change sets that contain the specified file?
, , TFS API. , , WIQL. , API, - , , . , , .
, TFS Data Warehouse. , , /.
TFS . .
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; } } }
For TFS 2012
Uri tfsUri = new Uri("http://xxx.xx.xx.xxx:8080/tfs2012"); TfsConfigurationServer configurationServer =TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(new[] {CatalogResourceTypes.ProjectCollection },false,CatalogQueryOptions.None); foreach (CatalogNode collectionNode in collectionNodes) { // Use the InstanceId property to get the team project collection Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]); TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId); WorkItemStore workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore)); string query = "SELECT [System.Id] FROM WorkItems where [Assigned to]=@Me"; WorkItemCollection queryResults = workItemStore.Query(query); }
For TFS 2013, the following code works to access the TFS project. Information:
var tfsUri = new Uri("http://tfs.xxx.xxx.com:8080/tfs/myCollection"); var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri); tfs.EnsureAuthenticated(); var iis = tfs.GetService<Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore>(); // here access to a particular Project with its name var uriWithGuid = iis.Projects["My project name"].Uri;
Right-click the file in Solution Explorer and select View History. You will get a list of change sets. Double-clicking on a set of changes will bring up a dialog in which you can see the related work items.