DCSIMG
The TFS Build Definition List<T> OOTB UITypeEditor - Oshry Horn

Oshry Horn

The TFS Build Definition List<T> OOTB UITypeEditor

A while back I came a problem:

I needed to build for a client an activity  that runs on an unknown number of projects and builds them with DevEnv 2005/2008/2010.

I needed to create an editor that allows the user to select projects to be built in DevEnv and additional properties for each project such as “DevEnv version” and “Configuration to build”.

The problem was that I had very little time to do this.

This is where my good friend Baruch Frei came into the picture; He informed me that when I build a simple dumb object such as:

   1: using System.ComponentModel;
   2:  
   3: namespace BuildDemosB
   4: {
   5:     public class DevEnvCompilationItem
   6:     {
   7:         [Category("Properties")]
   8:         public string Project { get; set; }
   9:  
  10:         [DisplayName("Compiler Name")]
  11:         [Category("Properties")]
  12:         public DevEnvType CompilerName { get; set; }
  13:  
  14:         /// <summary>
  15:         /// Specifies whether Clean and then build the solution or project with the specified configuration. Default is false
  16:         /// </summary>
  17:         [Category("Properties")]
  18:         public bool Rebuild { get; set; }
  19:  
  20:         #region Methods
  21:  
  22:         public override string ToString()
  23:         {
  24:             return string.IsNullOrEmpty(Project) ? "New" : Project + "=>" + CompilerName;
  25:         }
  26:  
  27:         #endregion
  28:     }
  29: }

and add a List<T> of that object to the builds “Process Template” as an argument like this:

image

What we will see in the “Process” tab of the “Edit Build Definition” window is the Microsoft “out of the box” editor of the List<T> object in TFS build definition.

This editor will hand us the functionality of adding and removing objects of type T to and from the list as well as to edit each of the public properties of the object.

image

On the left side you see the object in the list, displayed by their ToString() method, and on the right you see a properties grid of the selected object on the left.

What is also nice is that if you have in your object properties such as Boolean or Enum the properties grid will inflict those restrictions in the form of a drop down. 

 

Easy and fast.

 

In my next post I will show how to use some of Microsoft's internal UITypeEditors with the OOTB List<T> editor.

Comments

Kumar said:

Thanks for posting this.

Well, what's that CSS code that was pasted? What is it for?

{ .csharpcode, .csharpcode pre ......}

Can you please describe this?

Thanks.

# July 14, 2011 3:21 PM

Oshry Horn said:

Hi Kumar,

First of all, my pleasure. :)

If you mean these attributes:

* [DisplayName("Compiler Name")]

* [Category("Properties")]

They determine the way in which the property is displayed in the properties grid

* [DisplayName("")] - The name to display for the property.

* [Category("")] - The section under which the property is displayed.

# July 14, 2011 3:37 PM

Anthony said:

Under your BuildDemosB code snipit and just before the first image all we see is .csharpcode, .csharpcode pre { font-size: small......}

Looks like another code snipit that the browser can't display. I've IE and Chrome.

# July 14, 2011 4:13 PM

Oshry Horn said:

I see what you mean.

I was using a bad "code sipped add-in".

Fixed it now.

Thanks!

# July 14, 2011 6:34 PM

Kumar said:

Thanks.

Waiting for your next post to customize some of UITypeEditors

# July 18, 2011 5:09 PM

Oshry Horn said:

This post is a sequel to a previous post - The TFS Build Definition List<T> OOTB UITypeEditor.

# July 19, 2011 3:23 PM

Kumar said:

I'm unable to refer the custom object under Argument Type. DevEnvCompilationItem is mising.

Do I need to add the assembly anywhere else in the template?

Waiting for your early reply.

# July 26, 2011 10:33 AM

Oshry Horn said:

Hi Kumar,

Yes, in order to refer to the class from the template you must do the following: Take the project's dll/'s and add it/them to the folder in the source control to which the build controller you're using is referring as its assemblies directory.

# August 15, 2011 1:52 PM

Xabi said:

Hello Oshry,

I'm using a simple List<T> as a Argument Type and it automatically adds a UI in order to fill those properties of T. It works fine but when editing at "Queue new build" time that list and removing list items or modifying a property of an item doesn't have any effect. It still stores those values of the list that it had at the beginning, the ones that I added editing the build definition. Obviously I know that because I print all list's values on screen and they keep unchanged. Do you have any idea why could be that?

Thanks in advance,

Xabi

# October 24, 2012 9:17 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: