Customize Team Build 2010 – Part 3: Use more complex arguments

by Ewald Hofman 28. April 2010 02:36

In the series the following parts have been published

  1. Part 1: Introduction
  2. Part 2: Add arguments and variables
  3. Part 3: Use more complex arguments
  4. Part 4: Create your own activity
  5. Part 5: Increase AssemblyVersion
  6. Part 6: Use custom type for an argument
  7. Part 7: How is the custom assembly found
  8. Part 8: Send information to the build log
  9. Part 9: Impersonate activities (run under other credentials)
  10. Part 10: Include Version Number in the Build Number
  11. Part 11: Speed up opening my build process template
  12. Part 12: How to debug my custom activities
  13. Part 13: Get control over the Build Output
  14. Part 14: Execute a PowerShell script
  15. Part 15: Fail a build based on the exit code of a console application
  16. Part 16: Specify the relative reference path


 

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.

image

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

image

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.

image

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

image

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.

image

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

image

Open the properties window to change the properties of the ForEach activity. Change the following properties

Property Value
TypeArgument String
Values SourceFiles

 

image

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 (…)

image

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

image

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

image


 

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

Tags:

Team Build | VSTS 2010

Comments

5/25/2010 12:19:10 PM #

JimSimmons

Hello again,

I'm working on this type of deployment for our website now, and I'm trying to customize this to work with our solution. I'm not a programmer, but I'm one of the build managers and I've been put in charge of automating our build process. I'm trying to get this to call a cmd file that will robocopy the built files to where they need to be. What exactly does the """{0}\{1}"" ""{2}""" mean here?

String.Format("""{0}\{1}"" ""{2}""", BinariesDirectory, item, Destination)

Also, is it possible to do this? My robocopy script is basically "robocopy %1 %2" If I put the script name in "FileName", "deploy_project.cmd" or some such file name, I'm assuming the EnvironmentVariables could pass in the directories for the script to copy from and to.

Thanks. -Jim

JimSimmons United States |

5/25/2010 10:25:47 PM #

Ewald Hofman

The string.format (msdn.microsoft.com/en-us/library/b1csw23d.aspx) basically just replaces {0} with the value of BinariesDirectory, {1} with item and {2} with Destination. Compare it with %1 and %2 for batch files.

To execute robocopy, you can use the InvokeProcess activity. You can pass then the file (robocopy) to execute and the arguments FileName and deploy_project.cmd.

Good luck.

Ewald Hofman Netherlands |

5/28/2010 1:16:30 PM #

JimSimmons

Awesome! I've almost got this working. My last question. Is there any way to get the output from the robocopy script into the build log? It copies successfully, but I don't see in the build log where it calls my robocopy.cmd file. It looks like above that the invokeprocess shows up in your build log. Mine doesn't. Is there a different type of logging that I should be doing to pick it up?

Thanks again for all of you help. You have answered many of my questions, and have been very valuable during this setup for me. I am very grateful. -Jim

JimSimmons United States |

5/29/2010 11:27:45 PM #

Ewald Hofman

See www.ewaldhofman.nl/.../...on-to-the-build-log.aspx to send information to the build log

Ewald Hofman Netherlands |

7/14/2010 9:48:40 AM #

john Roh

Thanks for the great information that I was able to follow and tried to set up the TFS 2010 auto build.

But it seems like build process is displaying what I passed but the actual command doesn't get implemented.

The build process message shows the work flow I updated as below.

For each<String>
   Sequence
      Invoke Process
          robocopy xxxxxxx

Since my robocopy.exe is located at c:\scripts, I updated WorkdingDirectory to "C:\scripts" when I need the file name.
I even try to call a bat file but it's not doing anything.

Would you be able to help me out??

Thank you so much,

John.

john Roh United States |

7/14/2010 11:55:10 AM #

john Roh

Actually, robocopy is the one was the issue.

Now, the work folow works the way how I wanted.
Thanks so much for the great post and congratulation on the 2nd place at the world cup.
I wish the Nerthanland winning!!!!

john Roh United States |

4/12/2011 1:43:25 PM #

Brandon D

The link is dead =( it redirects to www.ewaldhofman.nl/.../...on-to-the-build-log.aspx

Brandon D United States |

4/12/2011 11:58:47 PM #

Ewald Hofman

Thanks. The correct link is www.ewaldhofman.nl/.../...on-to-the-build-log.aspx

Ewald Hofman Netherlands |

7/14/2010 10:23:56 AM #

john Roh

Hello, Jim?

I found this forum at www.ewaldhofman.nl/.../...e-complex-arguments.aspx
and saw your post.
I wonder whether I could get some help from you.

I set up the TFS 2010 build but my robocopy doesn't do anything even though my work flow got set up based on how Ewald shows on the forum.
If you could be help me, I can write you further.

Thank you,

John.

john Roh United States |

7/14/2010 11:55:32 AM #

john Roh

Actually, robocopy is the one was the issue.

Now, the work folow works the way how I wanted.

Thanks,

john

john Roh |

11/9/2010 5:32:27 AM #

trackback

Part 14: Execute a PowerShell script

Part 14: Execute a PowerShell script

Ewald Hofman |

11/10/2010 9:14:19 AM #

pingback

Pingback from blogs.like10.com

TechDays 2010 Presentations « Microsoft Team Foundation Server, SharePoint Server, .NET, and SQL Server

blogs.like10.com |

5/31/2011 8:21:59 AM #

trackback

Ewald’s posts on TFS Build 2010

Ewald Hofman , an ALM MVP, has written a great series of blog posts on Team Build in Team Foundation Server 2010.  The 2010 release introduces Windows Workflow as the overall orchestrator of the build process.  Ewald walks you through quite a few topics related to this and the other new features.  Check it out! 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 Part 16: Specify the relative reference path Technorati Tags: tfs 2010 , team build , windows workflow

Buck Hodges |

10/27/2011 6:18:14 PM #

pingback

Pingback from justaprogrammer.net

Continuous Integration with TFS2010, MSDeploy & VSDBCMD « Just A Programmer

justaprogrammer.net |

Comments are closed

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen


ClusterMap

Statistics

Statistics created at 09 Sep 2009

121 posts
488 comments
323 raters
1858129 visit (1043 per day)
17 users online

Recent comments

Comment RSS