Home > 2010, Team Build, TFS, TFS2010, Visual Studio > Customize Binaries Folder in TFS Team Build Part-2

Customize Binaries Folder in TFS Team Build Part-2


In this post I will go through a different way to accomplish what I posted in Part-1. Actually this approach is way simpler and less error prone than the first one.

I will create a new configuration named TFS, change the output path for each project for that configuration to  SolutionPath\bin\Projectname, Create a team build project and update Team build template.

Create a New Configuration

We want to create a new configuration for TFS team build and we don’t want to change the Release or Debug configurations. To do so

  • Right click on the solution
  • Click configuration manager menu

  • From the “Active solution configuration” drop down select <New…>

  • Type TFS in the name textbox
  • Select the configuration to copy configuration from (e.g. Release, or debug)
  • Click OK

  • In the Solution configuration, I am changing the Active Solution Platform to Mixed Platform because the projects in the solutions are targeting different platforms

  • Click Close

Preparing the Projects in the Solution

The following steps will change the output path from bin folder to SolutionPath\bin. I my solution I had a webApplication and a windowsApplication

  • Make sure that the TFS Configuration is selected
  • Change the Output location for each project on the solution to ..\bin\ProjectName.
    • Right click on the projectà properties
    • Click the build tab
    • Fill the “output path” textbox with ..\bin\ProjectName

  • Build the solution to make sure it is working

  • Check in the solution

Create a new Team Build

  • Open Team Explorer
  • Right click on the Builds node
  • Create a new Build, I named it CustomizeBinariesFolder
  • In the Process Tab
  • Expand Items to build
  • Select the solution we configured above
  • Expand Items to build
  • Click the ellipsis next Configurations to Build

  • Type TFS under Configuration and the Platform of that configuration
  • Fill the other fields as you want

Create new Team Build Template

  • Edit your Team Build Definition
  • Go to the process tab
  • Under Build Process Template click the New… button
  • Select an existing template that you want to copy, I am selecting the DefaultTemplate
  • Name the new File
  • Click OK

  • Save the definition
  • Open Source Control from Team Explorer
  • Get latest from BuildProcessTemplates

  • Open CustomizeFolderTemplate.xaml
  • Find “Run MSBuild for Project” Activity under “Try to Compile the Project” block.
  • Clear the OutDir property

  • OutDir property over writes the default output path on each project. By Clearing the OutDir property for the MsBuild Activity, Team build will use the Output Path defined in the project. In my case, C:\Builds\{AgentNumber}\Lajak\CustomizedBinariesFolder\Sources\WindowsFormsApplication1\bin
  • Now we want to copy the contents of the bin folder from the above path (i.e. solutionPath\bin) to the binaries folder
  • Add Copy Directory Activity under Run MsBuild for Project

  • Change the Source Property to IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “bin”), which means, Path of solution file + “\” + bin. By using the combine method we don’t have to worry about the Locale of the machine
  • Change the Destination property to BinariesDirectory
  • Save the Template
  • Go to Source Control Explorer and Check in the Template
  • Run the Team build definition that uses the template you have just modified. I am building the CustomizedBinariesFolder Definition


  1. opv
    October 4, 2011 at 12:59 pm

    Microsoft really complicates things, stuff that’s simple with ant for example

    • Lajak Technologies Inc
      October 4, 2011 at 11:09 pm

      The problem is MsBuild treats a solution as one project. You can set OutDir to String.Empty if you want to keep the binaries in the bin folder of each project

      • operaza
        October 6, 2011 at 2:09 pm

        Yes but there is also permissions stuff involved to get this working right I guess.
        The bin folders are created after clearing outdir in the directory created by the build agent when running the build definition but it fails to copy in my case in the last step with TFS warning TF270003.
        Thanks for sharing

  2. operaza
    October 6, 2011 at 3:47 pm

    It was not permission related my problem above. I had to change
    IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “bin”)
    to
    IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “\bin”) or
    IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “WindowsFormsApplication1\bin”) in this case to get it working.

    Do you know is there is a variable I can use for the Project name (WindowsFormsApplication1), for a solution containing several projects
    Thanks a lot for sharing, I appreciate it

  3. November 28, 2011 at 10:27 am

    I keep getting TFS|x64 is invalid tried mixed platforms I get the same error:
    “The specified solution configuration “TFS|Mixed Platforms” is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform=”Any CPU”) or leave those properties blank to use the default solution configuration.”

    • Lajak Technologies Inc
      November 28, 2011 at 10:38 am

      When are you getting that error? What type of project are you building?

      • November 28, 2011 at 11:08 am

        I get it when ever I kick off the build script. I removed the copy from the workflow until I get this first step working. I was able to have soem success with your first solution to this seperate folder issue but couldn’t get the webapp published into a seperate folder. mixed projects windows services and webapp in one solution

      • Lajak Technologies Inc
        November 28, 2011 at 11:22 am

        How do you publish the web application? Are you passing extra paramters to msbuild? That may not work if you have other type of applications (i.e. windows apps, libraries …etc) Try to run the build on an isolate web application as a proof of concept.

  4. Stephen
    February 7, 2012 at 7:45 pm

    Your copy directory code does not add up.

    If you copy the solution folder \bin then you are missing the project level that was added in.

    This leaves you with a reference to C:\SomePath\MySolution\bin
    That is not what the first steps setup. They setup a path of C:\SomePath\MySolution\MyProject\bin\MyProject

    At least that is how mine comes out.

  5. Stephen
    February 7, 2012 at 7:48 pm

    The two dots where hard to see.

    The path is ..\bin\project\

    I put in bin\project\

    Once I added the ..\ it all worked perfectly. Thanks!

    • Lajak Technologies Inc
      February 7, 2012 at 10:42 pm

      Cool, I am glad that it worked for you. Let me know if you have any other questions.

      Cheers
      A.

      Stephen :

      The two dots where hard to see.

      The path is ..\bin\project\

      I put in bin\project\

      Once I added the ..\ it all worked perfectly. Thanks!

  6. zaheer abbas
    October 17, 2012 at 7:52 am

    This is not working when the project has the website or web application. Build is segregating into seperate folders but it is not copying the content files.

  7. Moses
    June 7, 2015 at 8:43 am

    Hi, i’m stuck in the phase where you change all output paths to ../bin/projectName . after doing that, building and trying to debug locally -> it breaks. why do you change the paths? how can i solve this one?

  8. Moses
    June 7, 2015 at 10:05 am

    Hi again, I decided to skip the part of changing the relative path for each project, once i did that and continued with the template configuration, i got a succesful build, to my sources path at the server, and the drop folder remained empty (only logs). so this is basically great progress for me, cos now what i’d like is to just copy some of the binaries to the drop folder with a script. is there any way i can fire post build event (of the build server) that tells it to copy a specific folder to the drop folder? thanks again.

    • Lajak Technologies Inc
      July 14, 2015 at 8:58 pm

      HI Moses,

      Sorry I was blocking all comments because of the amount of spam I was getting. Do you still need help with the issue. Cheers

      • Moses
        July 15, 2015 at 2:19 am

        Hi,
        actually i’m not working on it for the last 3 weeks. but i’d love to talk to you and maybe get some more tips on how to achieve custom behavior for build server.
        can i get your email please?

    • Lajak Technologies Inc
      July 15, 2015 at 2:43 pm

      I recommend you don’t customize the XAML template and do all your customization in powershell instead. In TFS2015, a new Build engine will be shipped. Although the XAML engine is still supported, the future will be in the new Build engine

  1. July 31, 2011 at 12:10 am
  2. August 4, 2011 at 1:05 pm

Leave a comment