Scanning history for the changesets that had policy override – simple usage of QueryHistory

This needs references to Microsoft.TeamFoundation.Client.dll and Microsoft.TeamFoundation.VersionControl.Client.dll - it's intentionally simple and you can easily change the loop to include more information as desired, it's just to show usage of the API mainly.

Note that since we (intentionally) go backwards in our changesets via the IEnumerable, the order of the output will be reverse chronological.

For those wondering "why IEnumerable?" - it's mainly because the query (in general) could match thousands (even millions, of course) changesets.  We don't hammer the server with getting them all in a single call (that'd take awhile to build up and send back to the client), so as you probably notice from the http traffic we get the matching changesets back in chunks from the server.  This means a better user experience (as you don't have to wait forever for the whole collection) while still maintaining an easy-to-use API.  We considered using IEnumerable<Changeset> for this situation but we wanted to make things easier for some code that needed to interact with Everett.

D:\task1\vset\SCM\SourceControl\CommandLine>getoverridechangesets dogfood .
Changeset 7662 had 2 policy failures and an override comment of "new branch"

using System;

using Microsoft.TeamFoundation.Client;

using Microsoft.TeamFoundation.VersionControl.Client;


class Program


    static void Main(string[] args)


        if (args.Length == 0)


            Console.Error.WriteLine("Usage: GetOverrideChangesets <server> [path]");



        TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(args[0]);

        VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));


        string path = args.Length == 1 ? "$/" : args[1];

        IEnumerable changesets = vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, null, null, null, int.MaxValue, false, false);

        foreach (Changeset changeset in changesets)


            if (changeset.PolicyOverride.PolicyFailures.Length > 0)


                Console.WriteLine("Changeset {0} had {1} policy failure(s) and an override comment of \"{2}\"",









Comments (4)
  1. Buck Hodges says:

    I recently had to put together a list of links to code samples.&amp;nbsp; This isn’t even close to comprehensive,…

  2. MOC Curriculum : Course 2631A Optimizing the Software Development Lifecycle with Microsoft Visual Studio

  3. Buck Hodges says:

    I recently had to put together a list of links to code samples. This isn’t even close to comprehensive,

Comments are closed.

Skip to main content