by Ewald Hofman
27. May 2010 21:45
In the series the following parts have been published
- Part 1: Introduction
- Part 2: Add arguments and variables
- Part 3: Use more complex arguments
- Part 4: Create your own activity
- Part 5: Increase AssemblyVersion
- Part 6: Use custom type for an argument
- Part 7: How is the custom assembly found
- Part 8: Send information to the build log
- Part 9: Impersonate activities (run under other credentials)
- Part 10: Include Version Number in the Build Number
- Part 11: Speed up opening my build process template
- Part 12: How to debug my custom activities
- Part 13: Get control over the Build Output
- Part 14: Execute a PowerShell script
- Part 15: Fail a build based on the exit code of a console application
- Part 16: Specify the relative reference path
In the build you can set the verbosity to different levels to get diagnostic information from the activities that are executed. The information from the activities that come out of the box are great, but if you could add your own diagnostic information would be wonderful.
To add this information is pretty simple.
- Add a reference to the Microsoft.TeamFoundation.Build.Workflow assembly. You can find it in the folder C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies
- Then add a using statement to the namespace Microsoft.TeamFoundation.Build.Workflow.Activities
- You can now add the line context.TrackMessage(“My diagnostic information”); to show the information in the build log. You can also specify the importance of the message to indicate in which Verbosity it will be shown. The following table shows when the message will be shown.
| Verbosity |
Importance |
| Minimal |
- |
| Normal |
High |
| Detailed |
Normal |
| Diagnostic |
Low |
I created an activity with an argument that reports that argument back to the build log, also with the different possibilities of presenting the information.
using System.Activities;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Build.Workflow.Activities;
namespace BuildTasks.Activities
{
[BuildActivity(HostEnvironmentOption.All)]
public sealed class DiagnosticInformation : CodeActivity
{
public InArgument<string> TextIn { get; set; }
protected override void Execute(CodeActivityContext context)
{
string textIn = context.GetValue(this.TextIn);
context.TrackBuildMessage("Message: " + textIn);
context.TrackBuildMessage("Message (High importance): " + textIn, BuildMessageImportance.High);
context.TrackBuildMessage("Message (Normal importance): " + textIn, BuildMessageImportance.Normal);
context.TrackBuildMessage("Message (Low importance): " + textIn, BuildMessageImportance.Low);
context.TrackBuildError(textIn);
context.TrackBuildWarning(textIn);
}
}
}
When you run add the activity to your Build Process Template and run the build, you will see the following result for the different verbosities.
| Verbosity |
Result |
| Diagnostic |
 |
| Detailed |
 |
| Normal |
 |
| Minimal |
 |
You can download the full solution at BuildProcess.zip. It will include the sources of every part and will continue to evolve.