Thursday, October 13, 2011

How to get changeset information using TFS API?

_________________________________________________________________________________

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;

public void GetChangesetsInfo()
        {
            TfsTeamProjectCollection proj_coll = new TfsTeamProjectCollection(new Uri("http://NvnTfsserver:8080/tfs/defaultcollection/"), new System.Net.NetworkCredential(username, password));
            proj_coll.EnsureAuthenticated();

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

            //Following will get all changesets since 20 days. Note : "DateVersionSpec(DateTime.Now - TimeSpan.FromDays(20))"
            System.Collections.IEnumerable history = vcs.QueryHistory("$/Stakeholders Test Project", LatestVersionSpec.Instance, 0, RecursionType.Full, null, new DateVersionSpec(DateTime.Now - TimeSpan.FromDays(20)), LatestVersionSpec.Instance, Int32.MaxValue, false, false);

            foreach (Changeset changeset in history)
            {
                Console.WriteLine("Changeset Id: " + changeset.ChangesetId);
                Console.WriteLine("Owner: " + changeset.Owner);
                Console.WriteLine("Date: " + changeset.CreationDate.ToString());
                Console.WriteLine("Comment: " + changeset.Comment);
                Console.WriteLine("-------------------------------------");
            }
        }

 

9 comments:

  1. Useful indeed, QueryHistory() was just what I needed to identify changesets without work items

    ReplyDelete
  2. Excellent. Thanks for this. Exactly was I was looking to do.

    ReplyDelete
  3. Hi Naveen,
    This error pops up when i try to run the code. Am I missing anyting ? 'Microsoft.VisualStudio.Services.Common, Version=12.0.21005.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

    ReplyDelete
  4. Hi Bella,
    What version of VS you are using, couple of options you can try:
    Make sure you are referencing the correct dll.
    Try to use latest version of Microsoft.VisualStudio.Services.Common dl.
    Refer this link if it helps - https://roadtoalm.com/2014/08/01/error-in-tfs-2013-build-could-not-load-file-or-assembly-microsoft-visualstudio-services-webapi/

    ReplyDelete
  5. What packages are using to include the TFS API ? (nuget?)

    ReplyDelete