Creating a Team Deploy TFS Build

  • In Team Explorer, create a new build in your Team Project by right clicking on Builds and choosing “New Build Definition”
New Build Definition
  • Give it a name such as “Build and Deploy”
  • Create a workspace (Cloak other folders in your project that don’t need to be part of the build. This helps the speed up your build because otherwise the server will try to get all source files in the project)
  • Leave Project File name as is but click on the “Create” button to create a new TFSBuild.proj file.
  • Next choose the solution you want to build, then the configuration type. I recommend leaving the default.
  • Choose any options that you want to enable for running tests and/or code analysis. I would recommend leaving these unchecked for now and once you verify everything is working then go back and enable the options you want.
  • In TFS 2008, you can choose retention policies. This will help prevent builds from filling up your server disk space quickly. I usually choose Keep 7 latest.
  • the next options are for the Build Defaults. Choose the appropriate build agent. If unsure, just leave the default. Then choose the share where you want to copy the staging files.
  • The last option is “Trigger”. The "build and deploy" build should be separate from the continuous integration build. I recommend leaving the default “Check-ins do not trigger a new build”.
Build Trigger
  • Finally click “OK” to create the build type.

Creating the build definition will create the TFSBuild.proj that contains the basic options that were selected in the wizard. The following steps will customize the TFSBuild.proj file created. This file is a Xml file based on MSBuild.
  • To modify the TFSBuild.proj file, located the file under Source Control -> $/YourTeamProject/TeamBuildTypes/Build and Deploy (You can also navigate directly to this file by right clicking on the build definition and choosing "View Configuration Folder".)
  • Check out and open the TFSBuild.proj file to configure it to use Team Deploy
  • Find the comment <!—Do not edit this -> and add the following line underneath the one that is already there. It should look something like the screenshot below
<Import Project="$(MSBuildExtensionsPath)\TeamDeploy\TeamDeploy.Tasks.targets" />
  • Scroll to the bottom of the TFSBuild.proj file to the <PropertyGroup>. Overwrite the Property group with the following (Adjust the paths for your specific environment):
    <KillAppPathFilename>c:\Program Files\PSTools\pskill2.exe</KillAppPathFilename>
    <RemoteExecutePathFilename>c:\Program Files\PStools\psexec2.exe</RemoteExecutePathFilename>

  <!-- Deploy MSI  -->
  <Target Name="AfterEndToEndIteration">
    <CallTarget Condition="'$(IsDesktopBuild)'!='true'" Targets="DeployMSITargetVirtuals" />

  <Target Name="DeployMSITargetVirtuals">
    <Deploy DeployScript="$(SolutionRoot)\..\..\Push Scripts\SampleDeploy.xml"
            BuildUri="$(BuildUri)" />

The copied Xml in the TFSBuild.proj should look something like this
  • Save and check-in the TFSBuild.proj file

The Deploy task uses a Xml Deploy Script that contains the information of what Msi(s) to deploy, additional tasks such as starting and stopping the service, and specifies the target machines. The following steps walks you through editing this file.

There are a few things to note here.
  • Team Deploy can
    • Kill 0 to many processes
    • Deploy/Uninstall 0 to many MSIs
    • Deploy MSIs to 0 to many Target Machines
  • Modify the xml appropriately for your environment. The GUID for the uninstalls are the MSI product codes. If the MSI is done correctly it will uninstall previous versions using the upgrade code, however they are usually unable to remove the same version of the MSI, this is why we have the separate step of uninstall.
  • The ExtraArgs element contains the SETUPENV variable that is used by the MSI’s custom action to copy the correct environment’s config file to the project’s. The custom action is a simple VBScript that copies the config file (not included with Team Deploy). Below is how the folder layout is. Ignore the “test” folder I added to exclude the other folder in my actual Program Files folder.

For more information on creating the MSI to support Team Deploy and automated deployments
Blog Post Deployments with TFS Part 2: How to create an automated deployment MSI
Sample MSI Solution: Automated Deployment MSI

Last edited Aug 22, 2009 at 7:41 PM by mikedouglas, version 7


No comments yet.