- Nothing can beat experience

Create a TFS Build Custom Activity to Read From File

I needed to create a Custom Activity that reads from an XML file and displays the values on the Build log. It’s very easy and I will not re-write how to do the basic Custom Activity, but if you are not familiar with that, you can see the following link: Use and develop custom build process activities

Here, I needed to add OutArgument to return the value that I got from reading the file. I will get the value from the file and assign that value to OutArgument.

OutArguemnt in TFS Custom activity

After that, I built the project and distributed the library (DLL) under source control where the build controller points for the custom assemblies. See the previous link for the MSDN on how to do that. Open your process template that you want to use the new custom activity and right-click on the Toolbox and browse to the created library as the following image.
Add custom activity for The Visual Studio Toolbox

Drag and drop your new custom activity, declare a new variable (MyValue) to hold the return value from the reading process as the following image.

ReadFromXML Activity

The Build summary will be as the following image.

Build Summary

The build log will be as the following image.

Build Log

Make the activity return a list of strings

We will need to define OutArgument as a <List<string>> and assign that in the execute method.

OutArgument as list of string

Declare a variable (MyValue) but this time the type is a <List<string>> too. Drag and drop a [For each] Activity of string and print each item in the list as follows:

ReadFromXML Activity for list of string

The Build summary will be as the following image.

Build Summary for list of string

Trending Tags