How to add an enum to a TFS build definition

Recently I was asked how you go about to create an enum/drow-down argument in a TFS build definition. It’s actually a quite easy thing to solve and requires very little code. But it does require a fair bit of plumbing and since I didn’t find an example on how to do this I’m posting the steps here.

This is the scenario: I want a drop-down argument in my build definition that’s bound to an enum value, i.e. let me select the build status from a known set of values:

image

First add an enum to a TFS build activity:

image

I’m assuming you’re familiar with the process of TFS build extensibility. If you need an example of how to create a TFS build activity see http://msdn.microsoft.com/en-us/library/hh850441.aspx for an example.

Next add an argument of the BuildStatusEnum type to your build definition:

image

To get the enum to show as drop-down you need to add metadata to render it correctly. Open the metadata editor in from the Metadata argument and add the BuildStatus argument as a parameter. Then specify Microsoft.TeamFoundation.Build.Controls.EnumPropertyEditor, Microsoft.TeamFoundation.Build.Controls as the Editor, this does the trick of rendering the enum as a drop-down in the build definition process later on. The EnumPropertyEditor is one of the built-in editors which is convenient to use instead of implementing this logic yourself. If you’re curious of what other editors there are then take a look at this post http://bartwullems.blogspot.se/2012/07/tfs-build-using-built-in-editors.html and dig deeper by using a .NET reflection tool to investigate the code.

image

That’s all you need to do to setup the design time experience, now you can go on and use the enum in the build definition as you intend to.

image

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>