In the series the following parts have been published
- Part 1: Introduction
- Part 2: Add arguments and variables
- Part 3: Use more complex arguments
- Part 4: Create your own activity
- Part 5: Increase AssemblyVersion
- Part 6: Use custom type for an argument
- Part 7: How is the custom assembly found
- Part 8: Send information to the build log
- Part 9: Impersonate activities (run under other credentials)
- Part 10: Include Version Number in the Build Number
- Part 11: Speed up opening my build process template
- Part 12: How to debug my custom activities
- Part 13: Get control over the Build Output
- Part 14: Execute a PowerShell script
- Part 15: Fail a build based on the exit code of a console application
In this post I will show you how you can add more complex arguments to hold for example a list of strings or a Custom class.
In Part 2, I have described how you can add new arguments to your build workflow. We are now going to add a copy files activity. I want that after the compilation of the solution, my files are copied to a location. So I need to specify the list of files to copy and the target location where the files should be copied to. So I need to add 2 arguments:
- Destination path
- Source files
For the destination path, we can use the plain String type (which is the default), but for the list of files we need an array of strings. To select that, click on the string which will open a dropdown with the option to select the type of the argument.

Choose the Array of [T] from the list, which will open up a new dialog

Change the value Int32 to String and confirm with OK. The type of the argument SourceFiles is System.String[] now. Don’t forget to use the Metadata option to decorate the arguments to show them nicely in the Properties Window.

To use the new arguments now, locate in the workflow the place where the projects are actually compiled

After the “Run MSBuild for Project” we will add the logic to copy the files that the user have configured to copy. Open the toolbox and go to the Control Flow tab.

Drag ‘n drop the “ForEach<T>” activity on the white rectangle after the “Run MSBuild for Project” activity.

Open the properties window to change the properties of the ForEach activity. Change the following properties
| Property |
Value |
| TypeArgument |
String |
| Values |
SourceFiles |

In the Body, my best practice is to first drop a Sequence activity so you are always able to add new activities afterwards. In the sequence, add the activity InvokeProcess from the tab “Team Foundation Build Activities”. Select the InvokeProcess activity, and open the Properties Window. Change the following properties
| Property |
Value |
| FileName |
“xcopy” |
| Arguments |
String.Format("""{0}\{1}"" ""{2}""", BinariesDirectory, item, Destination) |
Save the workflow and check in the changes to source control.
Now you can edit your build definition. When you choose the build template you just modified, you will see the properties you just added. When you select the SourceFiles property, you will get the button with the ellipsis (…)

When you click on the button you will get a new dialog where you can enter the items in the string collection

We enter now the a file that we want to copy from the Binaries folder to c:\temp, which is in my case ConsoleApp.exe and ConsoleApp.pdb. When you look in the build log, you see that it has copied every file I have specified

You can download the full solution at BuildProcess.zip. It will include the sources of every part and will continue to evolve.