Share via


Dictionary Editor for TFS Build process Definition Parameters Editing

Problem Statement

TFS does not provide out of box Editor for editing the build parameters of the type Dictionary. Because of this, there is no way a user can enter the values if the data type for the build parameter is dictionary type. We have many properties in the build process workflow template which are of type Dictionary. Because of this, the only way to edit the values is to open the workflow editor in Visual studio and enter the values there as VB code using Visual Basic expression editor. This is not very intuitive for the end user. Further because of this limitation,  these parameters cannot be modified at the time of queuing the build thereby restricting the usage of build definition editor. Also, the build administrators are usually not developers so it's not easy for them to edit the workflow and modify these parameters.                 

Introduction

This article provides step by step guide to using a custom dictionary editor to specify the values for the properties in these activities which are of IDictionary <string, string> type. This editor is not available out of the box in TFS build definition process parameter editor. In the absence of this custom editor the value for activity properties such as Maven properties has to be provided inside the workflow using visual basic expression editor  which is not very intuitive and definitely  not easy for the Java developers to use and cannot be changed at the time of queuing the build or editing the build definition. 

If the dictionary editor is not used then the parameter values for the parameter of type Dictionary<string, string> needs to be specified as given below in the workflow variable assignment activity as a VB expression using the VB expression editor.

Value to be assigned to the parameter:

=  New Dictionary(Of String, String) From {{"PropertyName1", "PropertyValue1"}, {" PropertyName2", " PropertyValue2"}, {" PropertyName3", " PropertyValue2"}, {" PropertyName4", "Critical"}}

The Dictionary editor is specified in the Process parameter Metadata Editor as shown below:

As <namespace.className, assemblyName>

 Download the Custom Dictionary editor from here CustomDictionaryEditor

Steps to Use Custom String Dictionary Editor

The Custom String Dictionary Editor is a custom UI editor which has been created for editing the parameters or arguments of type Dictionary<String, String> in the build metadata arguments in the Build Definition editor wizard. 

To use this editor in the TFS Build definition Metadata editor

  • Copy the assembly  DictionaryEditor.dll  at the following location  

            C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies

            You can also add it to the Global Assembly Cache.

  • Specify the editor name in the Process Parameter Metadata editor screen, in the editor text box  (as <namespace.className, assemblyName>) against the arguments of the type Dictionary<String, String> or IDictionary<String, String> e.g. Maven Properties, Ant Properties

             e.g. DictionaryEditor.StringDictionaryEditor, DictionaryEditor 

  • Restart the Visual Studio IDE. 
  • Open the Build Definition editor and click against the ellipses towards the right of the argument. The parameter which is specified as of type Dictionary<string, string> appears as shown below. Clicking on the ellipse opens the editor as shown below 

            The UI editor on clicking on the ellipse button on the right side of the parameter. 

  • Once the editor opens, the key-value pair can be specified in the property grid on the right-hand side of the above form as shown in the diagram above and on clicking the Add button this key-value pair gets added to the Dictionary collection. The members of the collection are shown in the list box on the left-hand side. 

            The required TFS workflow builds definition arguments of type IDictionary<String, String> can now be specified as key, value pairs. Argument name as key and argument value as value.

  • After entering the respective Key Name and Key Value in the property grid on the right of the form as shown below please click on the Add button at the bottom to add the key-value pair to the collection.

Clicking OK will save the collection values in the TFS database as the argument values and close the form.

Clicking Cancel will close the form without updating the values.

You can also remove any key-value pair by clicking on the key-value pair on the left side box and then clicking on the remove button.

Any values already saved in TFS are displayed on the left side of the form as a key-value pair in a list. 

Custom String Dictionary Editor

The custom string dictionary editor contains DictionaryEditor as the main class. The class DictionaryEditor inherits from the UITypeEditor class. It overrides two methods, the methods being EditValue and GetEditStyle.

The class contains a Dictionary object of type Dictionary<String, String> which is used to store the argument key-value pairs and when ok button is clicked it returns this object to the calling method which is called from the Build definition editor. 

In the GetEditStyle method, the code is written to instruct Visual Studio to open up a modal dialog whenever this method is called.

In the EditValue method, the logic that is executed when the user clicks on the ellipsis button is written.  For details, please refer to the source code for the Dictionary Editor which is included with this document.