The Build Explorer Improved (TFS2010)

Update:
I published the source code and download on CodePlex: http://buildexplorer.codeplex.com

Recipe For a Better Build Log Viewer

The build explorer of Visual Studio 2010 can be quite useless when  your build is becoming large. The performance is dramatic and you keep scrolling but will never reach the end of the log. That was the reason for me to take a look at the object model. We were investigating the bottlenecks of our build customizations and needed insight in the execution process. To start with the result:

image

For the readers that are interested in the TFS2010 API are some details below. The others can skip ahead to the conclusion…

Ingredients

A nice and tasty build log viewer consists of the following elements:

A TeamProjectPicker

image

The TeamProjectPicker is a very useful tool for connecting to TFS from your own applications.

var picker = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false);
if (picker.ShowDialog(this) == DialogResult.OK)
{
    TfsTeamProjectCollection tfs = picker.SelectedTeamProjectCollection;
    IBuildServer buildserver = tfs.GetService<IBuildServer>();

ProjectInfo project = picker.SelectedProjects[0];
}

A couple of Build Definitions

From the selected TeamProject we retrieve the available build definitions:

IBuildDefinition bd = buildserver.QueryBuildDefinitions(project.Name)

A dozen of Builds

For each build definition we can query the builds of last seven days as follows:

IBuildDetailSpec spec = bd.BuildServer.CreateBuildDetailSpec(bd);
spec.MinFinishTime = DateTime.Today.Subtract(TimeSpan.FromDays(7));
spec.QueryOptions = QueryOptions.None;
spec.InformationTypes = null;

IBuildQueryResult builds = bd.BuildServer.QueryBuilds(spec);

Remark: The spec is important because querying builds without a descent spec will return all build information at once resulting in very long load times!

The Build Details

From a queried build we can get the details by querying again using the URI that is available on the the IBuildDetails from the IBuildQueryResult.

IBuildDetail build = server.GetBuild(uri);

A Huge amount of Build Information

Finally we are able to retrieve tons of interesting information from the IBuildInformation node on the IBuildDetails!

IBuildInformation info = build.Information

image

The only thing that is left is put all this information into a TreeView! I’ve added some “templating” to put useful information from the “fields” of a build information node into the text of tree node. This makes it easier to read the log.

A Refresh Button

For refreshing I store the selected build (into the Tag of my form) and can update the build details of a running build with the following statement:

build.Refresh(new string[] { &quot;*&quot;} , QueryOptions.All);

And of course I wrote some code to update the current tree nodes with the newly retrieved information. As a hint: I used the IBuildInformationNode.Id property to relate the nodes so I could reuse the existing nodes to leave the tree intact.

Conclusion

With the TFS2010 API we are able to make a Build Explorer that outperforms the explorer of Visual Studio. It even has a refresh mechanism that makes it usable to track running builds. Of course we should have used WPF for the user interface, but hey, the original explorer is already build with that… This little tool gave us very much insight in our build process and showed us the bottlenecks that we would not have found otherwise. One of our extension points that only took a couple of seconds to execute was executed that often that it took 1,5h of our 4,5h daily build. Without doing anything useful actually…

Let me know what you think about it!