Home > Team Build, TFS, TFS2010 > Customize Binaries folder in TFS Team Build Part 1

Customize Binaries folder in TFS Team Build Part 1

A new approach is posted here


  • Output binaries must have the following structure

    –Binaries folder

    —-(Build configuration)

    ——–(Project name)

    ————-Binaries files


The default build template has few limitations that required some customization to meet our requirements. The following are the limitations found:

  • The workflow treats a solution as single project
  • The output of building projects in a solution doesn’t follow the same output directory structure when building in visual studio. For instances, web applications output binaries in the Bin folder while ClassLibrary and Windows applications projects output binaries into the Bin\(configuration) folder.
  • In visual studio, binaries are copied to a bin/(configuration) folder where “configuration” is the configuration of the build (e.g. debug, release..etc) whereas the team build outputs all binaries into one folder called Binaries and that folder doesn’t contain sub folders per project


I know of two ways to customize the binaries folder. First solution is to modify build template to:

  • Create a folder per project in the solution in the output folder
  • Copy the binaries from the bin folder of each project

Second solution:

  • Modify each project in the solution to output binaries into a common bin folder e.g $(SolutionDirectory)\Bin\$(Configuration)\$(ProjectName)
  • Team build to copy the contents of the bin folder to the binaries folder

This article is a walkthrough for solution 1. I will blog about the second solution in a different post

Modification to Projects

Assume we have the following projects in a solution:

  • Make the Output path for all projects to be the same for all configurations (e.g. debug, release …etc)

Creating new Team Build Workflow Definition

  • Create new Teambuild definition
  • Fill the necessary fields
  • Click on Process on the left
  • Show Details
  • Click the New button
  • Click browse next to “Select the file to copy”
  • Select the Default Template
  • Give it a name

  • Click OK
  • Fill the other fields you need. Make sure you select a configuration for the solution you are selecting
  • Save the build template
  • Browse to the BuildProcessTemplates folder
  • Get latest version of the template we just created

Changes to the Default Template to Meet the Requirements

  • Open the CustomBinariesFolderTemplate.xaml workflow xaml file created in the previous section
  • Click Collapse All

  • Expand On Agent

  • Expand the follow activities:
    • Try Compile, Test, and Associate Changesets and Work Items
    • Sequence
    • Compile, Test, and Associate Changesets and Work Items
    • Try Compile and Test
    • Compile and Test
    • For Each Configuration in BuildSettings.PlatformConfigurations
    • Compile and Test for Configuration
    • If BuildSettings.HasProjectsToBuild
    • For Each Project in BuildSettings.ProjectsToBuild
    • Try to Compile the Project
    • Compile the Project
  • Select MSBuild Activity
  • Set the OutDir property to “”

  • Remember we want to output the binaries into the Binaries folder\Configuration\projectFolder\
  • Add a CreateDirectory Activity under “RunMsBuild for Project”
  • Set the DisplayName property
  • Set the Directory property to

    IO.Path.Combine(BinariesDirectory, platformConfiguration.Configuration)

  • Add FindMatchingFiles activity

  • Set the MatchPatter property to IO.Path.Combine(IO.Path.GetDirectoryName(localProject),“**\*.csproj”). If you want to files of different types you need to use the following syntax:

    IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “**\*.vbproj”) & “;” & IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “**\*.csproj”)

  • Set the Results property to VSProjects. Notice that you will get the Error icon because VSProjects doesn’t exist. Make sure you have the Find Project files activity selected when you are adding the variable to make sure the variable is created in the appropriate scope
  • Create a new variable called VSProjects of type IEnumarable<string> ie IEnumarable(Of String)

  • Add ForEach<String> project found activity, a loop to create a folder in the binaries directory for each project found and then copy the contents of the bin/configuration or bin folder to that created folder below the binaries folder

  • Add a Create directory activity with the following code in the Directory property

    Path.Combine(BinariesDirectory, platformConfiguration.Configuration, Path.GetFileNameWithoutExtension(item))

  • Add a copy directory activity

  • Change the destination and the source properties to copy the files in the bin folder of in the source folder to the Binaries\project folder\ directory

  • Save the work flow build template and check in the template

  • Queue a build
  • When build is complete go to the binaries folder and notice that you have three folders, one per project.

Categories: Team Build, TFS, TFS2010 Tags: , ,
  1. Pradeep Y
    June 28, 2011 at 9:59 am

    Very Good Post…! Help me a lot.
    Can you blog the second solution also?

    • Lajak Technologies Inc
      June 28, 2011 at 10:10 am

      Sorry I had my laptop sent for repair and I didn’t have a chance to restore the TFS virtual machine. I will try to set it up tonight and have the post ready by the end of the week.


  2. Pradeep Y
    June 28, 2011 at 10:08 am

    Seems this not working for Web Applications. As it copying files only from “bin” folder, and in ASPNET web applications, bin folder only contains DLLs without Content (ASPX, …) files.

    While Copying the files, it copying only files from BIN, left all other files. Which is not expected behaviour.

    Any solution for this?

    • Lajak Technologies Inc
      June 28, 2011 at 10:11 am

      You can modify it to copy from the folder you want 🙂 I will take a look at it while I am blogging the second solution.


      • sonicm
        July 10, 2012 at 6:14 am

        I know there are newer solutions but I’d be very interested in seeing how this can work with web solutions?

      • Lajak Technologies Inc
        August 21, 2012 at 10:13 am

        Can you let me know what are you trying to accomplish? I will then gladly create part 3 of post.

  3. Marcin Zawadzki
    December 7, 2011 at 4:09 am

    I do not see “Team Foundation Build Activities” in toolbox.
    Should I install something more?

    • Lajak Technologies Inc
      December 7, 2011 at 9:50 am

      Which version of Visual Studio do you have?

  4. Lajak Technologies Inc
    August 21, 2012 at 10:12 am

    sonicm :

    I know there are newer solutions but I’d be very interested in seeing how this can work with web solutions?

    Can you let me know what are you trying to accomplish? I will then gladly create part 3 of post.

  5. November 30, 2012 at 4:21 pm

    Out solution had project files outside the Solution directory, so I modified it to actually read the project file paths from the solution file. Here is the code.

    System.Linq.Enumerable.Select(System.Linq.Enumerable.Cast(Of System.Text.RegularExpressions.Match)(System.Text.RegularExpressions.Regex.Matches(System.IO.File.ReadAllText(localProject), “Project\(.*?\s+=.*?””,\s+””(.*?\.*proj)””,”)), Function(m) m.Groups(1).Value)

    • November 30, 2012 at 4:21 pm

      This is for the Find Project Files step.

    • November 30, 2012 at 4:23 pm

      Your code helped me out a lot, thanks.

    • Lajak Technologies Inc
      November 30, 2012 at 4:24 pm

      Thanks for sharing that with the world 🙂

  1. July 30, 2011 at 11:44 pm
  2. September 19, 2011 at 8:04 am
  3. September 19, 2011 at 8:06 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: