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:
- Create a new Build Definition by opening up the Team Explorer panel in Visual Studio and navigating to the “Builds” portion of the tree
- Right click on “Builds” and choose “New Build Definition”
- 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)
- In the Process section , set the value for “Projects to build” to the .sln file of the project you want built
- 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.
2. Creating a new Build Definition
- 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
- 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.
- 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)
3. Creating new activities in the Build Process Template
- 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.
- 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.
- 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”‘
- 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)’
- Close the properties window and save the Build Definition
4. Customizing the build Process
- 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.
- 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.
- 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.