Geeks With Blogs

(Amazon Affiliate Ads)

Mike Parks Code.Where(c => c.IsTechnicalDebt).Refactor();
Using TFS and Team Build to deploy to Development, Integration, QA, Stage, Pre Production, or any other testing servers you have can be quite a bit of a challenge sometimes. I haven't really found a lot of documentation or best practices out there for it either. There are plenty of ways to move the files across each environment. I'm going to try this build definition out for a while and see how well it works. 

When I queue a new build definition up, I'm going to pass in the following parameters (they will be different each time I queue a new build so I can specify exactly what I need):

These parameters are used to tell my build definition which source control version I want to build and which environment I want to deploy the files to.  The GetVersion parameter can accept a changeset number, label, date, "W" (Version last fetched to your workspace), or "T" (latest version).  The DeployTo parameter can accept Dev, QA, or Stage. You can also default the parameters by setting the values in the .rsp file. See the following links for more information on how these are being used:

Building a Specific Version with Team Build 2008
MSBuild Conditional Constructs

Here's a sample build definition that uses the parameters:

<?xml version="1.0" encoding="utf-8"?>

<!-- DO NOT EDIT the project element - the ToolsVersion specified here does not prevent the solutions

     and projects in the SolutionToBuild item group from targeting other versions of the .NET framework.


<Project DefaultTargets="DesktopBuild" xmlns="" ToolsVersion="3.5">

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets" />















    <WorkItemFieldValues>System.Reason=Build Failure;System.Description=Start the build using Team Build</WorkItemFieldValues>

    <WorkItemTitle>Build failure in build:</WorkItemTitle>

    <DescriptionText>This work item was created by Team Build on a build failure.</DescriptionText>

    <BuildlogText>The build log file is at:</BuildlogText>

    <ErrorWarningLogText>The errors/warnings log file is at:</ErrorWarningLogText>









    <When Condition=" '$(DeployTo)'=='Dev' ">





    <When Condition=" '$(DeployTo)'=='QA' ">





    <When Condition=" '$(DeployTo)'=='Stage' ">








    <SolutionToBuild Include="$(BuildProjectFolderPath)/../../Development/Websites/MikesWebApplication/MikesWebApplication.sln">







    <ConfigurationToBuild Include="Release|Mixed Platforms">


      <PlatformToBuild>Mixed Platforms</PlatformToBuild>




  <Target Name="AfterDropBuild" >


    <!--Delete Previous Deployment-->

    <CreateItem Include="$(DeployPath)\**\*.*" Exclude="$(DeployPath)\**\Web.Config">

      <Output ItemName="PreviousDeployment" TaskParameter="Include" />


    <Delete Files="@(PreviousDeployment)" ContinueOnError="true" />


    <!--Define New Deployment Files To Be Copied-->


      <Compile Include="$(DropLocation)\$(BuildNumber)\Mixed Platforms\Release\_PublishedWebsites\**\*.*"

               Exclude="$(DropLocation)\$(BuildNumber)\Mixed Platforms\Release\_PublishedWebsites\**\Web.Config"/>




    <Copy SourceFiles="@(Compile)" DestinationFolder="$(DeployPath)\%(RecursiveDir)"></Copy>




Hope this helps! Leave me some feedback if you get a chance. Thanks everyone. Posted on Wednesday, August 5, 2009 3:49 PM | Back to top

Comments on this post: TFS - Deploying To Multiple Environments Using Team Build

# re: TFS - Deploying To Multiple Environments Using Team Build
Requesting Gravatar...
I did something similar, but I separated the build from the deploy so that I could control which TFS users could do the deploy and since you have to give administer a build rights to apply the MSBUILD parameters.
Left by Paul D'Anna on Aug 10, 2009 8:04 PM

Your comment:
 (will show your gravatar)

Copyright © MikeParks | Powered by: