In this post, I want to explain how you change the way that build information is displayed on the Build Details View. You can do some pretty crazy things if you really want to. We are just going to change the color of Build Messages. If you want more details on customizing the Log View, see my last post on the subject.

In the Log View of the Build Details View, messages are displayed as normal black text on the white background. So, they don’t stand out much. What I want to do is show you how to change the color of the messages so that they do stand out against all the other text.

Scenario:

Change the text of build messages from black to LightSteelBlue.

Steps:

We don’t have to do anything for messages to show up in the view. They already do that. All we need to do is change the way they show up. To do that we need to create a custom converter for the build information type “BuildMessage”.

There are a couple of things I would like to note here about the Convert method. The IBuildDetailView object gives you access to some addition information like IBuildServer if you need it. The IBuildInformationNode object is the build information that you are converting. The parentIndent value is how much you should probably indent your paragraph to keep the “tree-like” feel of the Log View. In the example below, I simply set the Margin of the new Paragraph to have a left margin equal to the parentIndent. This value is based on the Build Information hierarchy depth at which the build information is located.

Here is the code for the converter:

using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Build.Controls;

namespace CustomBuildInformationConverters
{
    class MessageConverter : IBuildDetailInformationNodeConverter
    {
        public object Convert(IBuildDetailView view, IBuildInformationNode node, double parentIndent)
        {
            Paragraph p = new Paragraph();
            p.Margin = new Thickness(parentIndent, 0, 0, 0);
            p.Foreground = Brushes.LightSteelBlue;
            p.Inlines.Add(node.Fields["Message"]);
            return p;
        }

        public string InformationType
        {
            get { return "BuildMessage"; }
        }
    }
}

But first, we need an AddIn (or VSP Package) that we can load into our Visual Studio Client at start up. I used the wizard to generate a new AddIn project that loaded at start up.

Here is the code I added to register/unregister my converter:

public void OnStartupComplete(ref Array custom)
{
    IVsTeamFoundationBuild VsTfBuild = (IVsTeamFoundationBuild)_applicationObject.DTE.
        GetObject("Microsoft.VisualStudio.TeamFoundation.Build.VsTeamFoundationBuild");
    if (VsTfBuild != null)
    {
        _converter = new MessageConverter();
        VsTfBuild.DetailsManager.RegisterLogViewInformationConverter(_converter);
    }
}

public void OnBeginShutdown(ref Array custom)
{
    if (_converter != null)
    {
        IVsTeamFoundationBuild VsTfBuild = (IVsTeamFoundationBuild)_applicationObject.DTE.
            GetObject("Microsoft.VisualStudio.TeamFoundation.Build.VsTeamFoundationBuild");
        VsTfBuild.DetailsManager.UnregisterLogViewInformationConverter(_converter);
    }
}

 

And Here is how the Log View looks now:

image

So, you may be wondering what other build information types already have converters. In the Microsoft.TeamFoundation.Build.Common assembly, you can find a list of all predefined Build Information Types. Just look for the class InformationTypes. Not all of those types, however, have existing converters. This is mostly because we only wanted to show you the important information on the Log View.

Here’s the list of Information Types that do have converters for TFS 2010:

  • ActivityProperties
  • ActivityTracking
  • AgentScopeActivityTracking
  • BuildError
  • BuildMessage
  • BuildProject
  • BuildStep
  • BuildWarning
  • ExternalLink
  • OpenedWorkItem

Enjoy!