How to Xcopy deploy using TFS 2010/2012


I need my VS2010/VS2012 build to perform an “Xcopy deployment” of my ASP.NET application to an existing virtual directory.


Customize the build template to use the CopyDirectory activity to copy the ASP.NET application to the virtual directory.


One of the benefits of ASP.NET development is the simply “Xcopy deployment”. ASP.NET applications require no changes to the registry and have no special installation requirements for the hosting server.  Therefore, you can use the drag-and-drop feature in Microsoft Windows Explorer, File Transfer Protocol (FTP), or the DOS Xcopy command to copy files from one computer to another.

The only prerequisite of this technique is the virtual directory in IIS must already be created and configured.

The goal of this build is to not have to install any special features or extensions in IIS to facilitate deployment of my ASP.NET application.  I want my environments to match production as close as possible and I never intend on installing IIS Extensions in production.

When you configure a build definition that builds and ASP.NET application the binaries directory and drop location contain a folder named _PublishedWebsites.  Each ASP.NET application built during the build will have a sub directory that contains all the files needed for the application.

To perform an “Xcopy deployment” we simply need to identify the source and destination directories.  We are going to store this information in arguments passed to the build.  To begin open the DefaultTemplate.xaml file in VS2010 and click the Arguments button at the bottom of the workflow designer to show the workflow arguments.  Add two string arguments  VDir and SiteDir. Now let’s add a nice coat of polish on our arguments.  Click the ellipses next to the default value of the Metadata argument to show the Process Parameter Metadata Editor window.  Click the Add button and enter in the following information and click OK.

Parameter Name – VDir
Display Name – Virtual Directory
Category – Deploy
Description – The full UNC path to the virtual directory to copy the website too.
Editor leave blank
Required leave unchecked
View this parameter when – Always show the parameter


Parameter Name – SiteDir
Display Name – Site Directory
Category – Deploy
Description – The sub directory of _PublishedWebsites to copy from.
Editor leave blank
Required leave unchecked
View this parameter when – Always show the parameter


We are simply going to add a CopyDirectory activity that uses the arguments we just created to perform the copy.  To begin we must locate the correct area of the build template to add our CopyDirectory activity.  I find the quickest way to do this is to click the Collapse All button at the top of the workflow designer window.  Now double click on the words Double-click to view on all of the following activities:

1.    Run On Agent
2.    Try Compile, Test, and Associate Changesets and Work Items
3.    Sequence
4.    Compile, Test, and Associate Changesets and Work Items
5.    Try Compile and Test
6.    Compile and Test
7.    For Each Configuration in BuildSettings.PlatformConfigurations
8.    Compile and Test for Configuration

When we configured the metadata for our arguments we left the Required checkbox unchecked.  This will allow users of this build template to leave the values for VDir and SiteDir blank if they are not building an ASP.NET application or simply do not want to deploy them.  Therefore, we need to check the value of the arguments to determine if we need to perform the copy or not.  In the toolbox expand the Control Flow tab and drag and drop the If activity right above the If Not Disable Test activity.  Click the double down arrows in the title bar of the if to show its contents. In the Condition text box enter the following:

Not String.IsNullOrWhiteSpace(VDir)

From the toolbox drag and drop a Sequence activity from the Control Flow tab onto the Then side of the If.  Change the DisplayName of the sequence to Deploy ASP.NET Application. We add a sequence here so that we can use multiple activities. Click the double down arrows in the title bar of the sequence to show its contents.  This is where we are going to add the activities needed to copy the ASP.NET application to the virtual directory in IIS.

Now we can add the CopyDirectory activity and set the properties to deploy our ASP.NET application during the build.  To get started simply drag and drop the CopyDirectory activity from the Team Foundation Build Activities tab into the Deploy ASP.NET Application sequence.  With the CopyDirectory activity selected set the following values in the properties window:

•    Destination – Vdir
•    Source  - BinariesDirectory + "\_PublishedWebsites\" + SiteDir

Now save your xaml file, check in your changes and queue a new build.

You can download a copy of the final file below.

TFS2010 DeployTemplate.xaml (55.16 kb)

TFS2012 DeployTemplate.11.1.xaml (75.68 kb)

Comments are closed