Search code examples
tfstfs-sdk

How to Find TFS Changesets Not Linked to Work Items


Is there a way, either via a query or programmatically, to identify all TFS Changesets that are NOT linked to a Work Item?


Solution

  • Sure, you can use the TFS API to do this very easily.

    public static void GetAllChangesetsWithNoWorkItems()
    {
        var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs2010/tfs/default"));
        var service = tfs.GetService<VersionControlServer>();
    
        var histories = service.GetBranchHistory(new ItemSpec[] { new ItemSpec(@"$/ProjectName/MAIN/BUILD", RecursionType.OneLevel) }, VersionSpec.Latest);
    
        foreach (BranchHistoryTreeItem history in histories[0])
        {
            var change = service.GetChangeset(history.Relative.BranchToItem.ChangesetId, true, true);
    
            if(change.WorkItems.ToList().Count == 0)
            {
                Debug.Write(String.Format("Work Item Missing for Changeset {0}", change.ChangesetId));
            }
        }
    }
    

    You can read this blog post on how to connect to TFS API Programmatically http://geekswithblogs.net/TarunArora/archive/2011/06/18/tfs-2010-sdk-connecting-to-tfs-2010-programmaticallyndashpart-1.aspx