Categories
Uncategorized

Deploying Web Apps with a customized Build Process in TFS

Use the steps below to setup the TFS Build server to copy built website(s) to a given directory(s)

1. Creating a new Build Definition

To setup an automatic build and deploy action, a customized build process template is required.  Setup a new build process template with parameters by following the steps below:

  1. Create a new Build Definition by opening up the Team Explorer panel in Visual Studio and navigating to the “Builds” portion of the tree
  2. Right click on “Builds” and choose “New Build Definition”
  3. Under the General section, supply a name. In the Build Defaults section, check the “This build copies outputs to a drop folder” check-box and select a folder somewhere. This is usually a share (Make sure that the “NT AuthorityNetwork service” (or whatever account the Build Controller runs under) has read/write permission here)
  4. In the Process section , set the value for “Projects to build” to the .sln file of the project you want built
  5. Under the Configurations to build section entry, set the build configuration (debug, release, dev, etc) you want built.  You will need to create a separate build definition for each configuration you want built.
Setting the properties for the Build Definitio

2. Creating a new Build Definition

  1. At the top of the Process section, there is a section that says “Build Process template”. Click on the “show details” on the right hand side of the screen and then click on the “New” button.  Choose “copy and existing XAML file” and enter a new file name
  2. In the source explorer, go to the “Build Process Templates” section under the project.  The new XAML file should be in there. Double-clicking this file will open it up in the Work flow designer.
  3. Create new input arguments for the Build Definition by selecting the “Variables” tab at the bottom of the screen and entering a new variable titled “DeployWebsiteTo” Set it as an “In” variable with a String Data-type.  (Note the image below shows two new variables titled DeployBusinessWebsiteTo and DeployPresentationWebsiteTo)
Creating new input variables

3. Creating new activities in the Build Process Template

  1. Click on the “Expand All” link on the upper right hand side of the pane. Scroll down until you find a box title “If DropBuild and DropLocation is set”. Open the toolbox and scroll down to the toolbox section labeled “Control Flow”. Drag an “If” activity onto the arrow below the “If Dropbuild..” section located above.
  2. In the Toolbox scroll to the section labeled “Team Foundation Build Activities” and drag a “CopyDirectory” action to the “Then” side of the “If” activity created in the work-flow.
  3. Right-click the icon in the new Copy Director and open the “properties” page. In the “Destination” field type the name of the variable created as an input parameter above “(DeployWebsiteTo)”. For the ”DisplayName” set it to “Copy Directory”. Under the Source enter the source directory as follows, substituting the name for your web application ‘BuildDetail.DropLocation + “_PublishedWebsitesWebsiteName”‘
  4. Close the properties for the Copy Directory activity and Open the ‘If’ Activity. Set the DisplayName to ‘If DeployWebsiteTo is set’ and the Condition field to ‘Not String.IsNullOrEmpty(DeployWebsiteTo)’
  5. Close the properties window and save the Build Definition
Creating the new build activities
Setting the Build Activity properties

4. Customizing the build Process

  1. Open the new Build Process if it isn’t already loaded and go to the Process section. Expand the “Build Process Template” by clicking the show details and make sure the new Build Definition created above is selected.
  2. Expand the ‘4. Misc’ section of the “Build Process Parameters” to see the new parameter created above. Set the directory (share) where the website should be deployed to.  Ensure the user account hat the Build Controller runs as has read/write access to this folder”. Save the Build Process.
  3. Queue a new build and verify that the website is copied to the directory specified in the parameters. You cannot change the DeployWebsiteTo” parameter when queuing a new build, it must be done by editing the build process.

By darylchymko

Code Wrangler and ultrarunner

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 )

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