Commentor Blog

When Quality Matters

Commentor A/S

When Quality Matters

Contact usSend mail

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2012

Retrieving the build history from Team Foundation Server using the Visual Studio 2010 SDK

In this short article I would like to demonstrate how to use the Visual Studio 2010 SDK to retrieve the Build History for a specific Team Project and Build Definition and retrieve the Change Sets and Work Items associated to the build. Before getting started we need to install the Visual Studio 2010 SDK.

The namespaces used in this sample are included in the following assemblies: 

  • Microsoft.TeamFoundationServer.Client
  • Microsoft.TeamFoundationServer.Build.Client -
  • Microsoft.TeamFoundationServer.VersionControl.Client
  • Microsoft.TeamFoundationServer.WorkItemTracking.Client 

 
using System;
using System.Diagnostics;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
 
namespace BuildHistory
{
    class Program
    {
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());
 
            var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("[TFS SERVER URL"), new UICredentialsProvider());
            tfs.EnsureAuthenticated();
 
            var buildServer = tfs.GetService<IBuildServer>();
            var versionControl = tfs.GetService<VersionControlServer>();
 
            var buildDetails = buildServer.QueryBuilds("[TEAM PROJECT NAME]", "[BUILD DEFINITION NAME]");
            foreach (var build in buildDetails)
            {
                Trace.WriteLine("Build: " + build.BuildNumber);
 
                var changesets = InformationNodeConverters.GetAssociatedChangesets(build);
                if (changesets == null)
                    continue;
 
                foreach (var summary in changesets)
                {
                    Trace.WriteLine("Changeset Summary: " + summary.ChangesetId + " " + summary.Comment);
 
                    var changesetItem = versionControl.GetChangeset(summary.ChangesetId);
                    foreach (var file in changesetItem.Changes)
                        Trace.WriteLine("Affected file: " + file.Item.ServerItem);
 
                    foreach (var workItem in changesetItem.WorkItems)
                        Trace.WriteLine("Work Item: " + workItem.Id + " " + workItem.Title);
                }
 
                Trace.WriteLine(string.Empty);
            }
 
            Console.ReadLine();
        }
    }
}
 

I hope you found this useful 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by christian.resma.helle on Wednesday, August 04, 2010 3:34 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Related posts

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Sunday, February 05, 2012 10:33 AM