DCSIMG
How to: Use The Internal Microsoft Custom UI Type Editors In TFS 2010 Build Definition - Oshry Horn

Oshry Horn

How to: Use The Internal Microsoft Custom UI Type Editors In TFS 2010 Build Definition

Let say that I want to enable clients to choose specific projects to publish from within a build definition.

I can obviously add a StringList argument to the build, and have users write the server paths of each project they want to publish as a open strings.

This off course leaves much room for errors on the client side, but farther more it just looks unprofessional!

I don’t want to write A custom UIEditor for this purpose for the following reasons: I’m lazy, no time, and most important I know that such a control exits!! I mean the control that enables us to choose which projects we want to compile as part of the build!

image

image

So now that I see that Microsoft is already using what I need all I have to do is find it and utilize it for my own use:

1) I will go to the arguments tab in the build definition template (possibly DefaultTemplate.xaml) and check what is the type of the variable that is using this UIEditor that I am after. In this case it is “Microsoft.TeamFoundation.Build.Workflow.Activities.BuildSettings”.

image

2) In our case this is actually not the type that I am looking for because this type contains both project and configurations, and I need only the Projects’ property type. By typing “new Microsoft.TeamFoundation.Build.Workflow.Activities.BuildSettings().ProjectsToBuild” you can see the type of the property is “StringList”.

3) I will create my own argument and set it to the desired type (since I’m looking for to using the same type of data. In this case a list of strings containing the Server Paths of Projects), and name it “ProjectsToPublish”.

image

4) Now, this part is a bit tricky – I will open “Reflector” and in it open the assembly in which the type I found (BuildSettings) is defined (Microsoft.TeamFoundation.Build.Workflow.Activities).

–If you don’t know where the assembly is, do a general search on your pc--

image

5) Then I will check out the “Editor” attribute of the property “ProjectsToBuild” of the type “BuildSettings”. in this case - "Microsoft.TeamFoundation.Build.Controls.BuildProjectListEditor, Microsoft.TeamFoundation.Build.Controls"

image

image 

6) At this point I will Edit the “Metadata” argument:

image

and get this window:

image

7) In the window I will add my new argument as a Process Parameter, and simply copy the editor’s name (that I found with the reflector) to the Editor textbox.

8) Save and check in the build template file.

9) Go to the “Process” tab of your build definition and press the “Refresh” button to refresh the build definition template.

image

 

That was easy, wasn’t it? :)

image

Works perfectly!

Notice that the editor class we are using is internal, and still it is not a problem!

image 

 

Enjoy! :)

Comments

Oshry Horn said:

As I’ve shown in here , it is easy and productive to use the Microsoft built in “UITypeEditor”s in TFS

# March 23, 2011 10:02 AM

Brandon D said:

Is it possible to override the editor's requirement that the items to build or items to publish be populated?

# April 5, 2011 7:23 PM

Oshry Horn said:

Hello Brandon,

If I understand you correctly it depends on the actual editor. If it is public you can inherit and adjust,

if not you can write your own (Its fairy simple).

Either way why does it bother you that you have to initialize the variable (in case its null) before using the editor to change it?

# April 6, 2011 12:02 PM

Brandon D said:

I can't figure out where the 'required' flag for that is being set. I've used reflector for hours on end searching. This is in the build definition setup if the default template is selected or any template I've made that was branched from it. I've checked in the XAML, reflectored the editor.... no luck.

# April 25, 2011 3:30 PM

Oshry Horn said:

Hello Brandon,

The 'required' flag for that is being set in the "Process Parameter Metadata Editor" right under where you define the editor for your type.

# May 1, 2011 12:37 PM

Kumar said:

Hi,

I've a requirement for customizing the BuildProjectListEditor which is internal to BuildSettings.

How to achieve this by tweaking the Grid in editor.

# June 23, 2011 1:20 PM

Oshry Horn said:

Hello Kumar,

Since BuildProjectListEditor is an internal class it cannot be altered.

However, if I remember correctly, the BuildProjectListEditor editor is made of a few other editors. You can use those editors to create a new object and alter utilize it with the builds default "List<T>" editor.

Give me some more details regarding what your trying to achieve, and I'll focus you even more...

I've got some demos and examples that could help.

For that you'll need to send me your e-mail. (HornOshry@gmail.com)

Good luck :)

Oshry Horn

# June 25, 2011 6:20 PM

Kumar said:

Hi Oshry,

Sent you a mail detailing about the task.

Please shoot out your opinions and samples if any.

Thanks.

# July 5, 2011 8:51 AM

Reusable Editors – TFS build arguments « dev.tfs said:

Pingback from  Reusable Editors &#8211; TFS build arguments &laquo; dev.tfs

# October 23, 2012 5:29 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: