TFS: Create a WebDeploy package using Team Build 2

TFS: Create a WebDeploy package using Team Build

During my session at the TechDays 2013 a reader of my blog asked me how to generate a WebDeploy package from Team Build. Here’s a post on this subject :)

Before starting here’s a brief reminder of what WebDeploy is:

WebDeploy is a tool to simplify the deployment of web applications or web sites on IIS servers. With WebDeploy an administrator can export or import a web site as a configurable package or can synchronize IIS servers.

In this post i’ll show you how you can create a WebDeploy package (.zip) based on your web application source files and the result of it’s build.

Configuring the solution

The first thing you can do is configure your web projet using it’s properties:

SNAGHTML367f113

Note that all these parameters can be overrides during a build if you want to centralized some of those parameters. In fact, all these parameters are MsBuild properties :)

Setting up a build definition

Before anything, you need to create a build definition using the default template and configure it to build your solution containing your web application:

SNAGHTML382aac1

If you start this build without any other parameters you will get in the output a folder named _PublishedWebSites containing your web application:

SNAGHTML384d26d

To create a WebDeploy package we will need to pass some specific values for MsBuild properties used in the Web deployment targets Microsoft.Web.Publishing.targets. Here are those properties we will override:

  • DeployOnBuild: a boolean to indicate if we want to deploy after building the web application.
  • DeployTarget: indicates the deployment action to perform.
  • DefaultPackageFileName : the name of the WebDeploy package to create.

The first parameter indicates that we want to start the deployment pipeline for Web applications in the solution we are compiling. By default this parameter is false, so we need to override this value with true.

The parameter DeployTarget specifies the action we want to do while deploying. When deploying you can do different actions (create a package or deploy), here we want to create a WebDeploy package only. For this we use the value Package which is the default value so no need to specify a value :)

The last parameter specifies, when executing from TeamBuild, the suffix which will be used in the name of the generated files. Usually this value is specified in the project properties but when using TeamBuild those properties are not used and the project name is used instead:

SNAGHTML39370be

To override this name we will use the DefaultPackageFileName property:

SNAGHTML39d0f2f

Now that we know the MSBuild properties to override we can update our build definition to include those. All you need to do is specify them in the “MsBuild Arguments” line in the Advanced section by using the MSBuild command line syntax “/p:DeployOnBuild=true;DefaultPackageFileName=WygwamTechDays.zip”:

SNAGHTML39fe5a0

Your build will now generate a WebDeploy package with the specified name. This package is available under the _PublishedWebSites directory:

SNAGHTML3a223e7

If you think that using the MSBuild parameters is too complex you can personalize your build template and add parameters like “Create WebDeploy Package” and “WebDeploy Package Name” and use those values to pass specific parameters to the MSBuild activity. Note that the MSBuild activity already have a DeployOnBuild parameter to simply even more :)

Using publishing profiles

With Visual Studio 2012 you can now create publishing profiles (.pubxml files). Theses files containes the WebDeploy parameters to use. You can easily create or use those profiles inside Visual Studio by doing a right click on your project and select Publish :

SNAGHTML3a852b4

You can create or us an existing publishing profile:

SNAGHTML3a9b9df

When you have created and added to source controls your publishing profiles you can use the PublishProfile parameter to use them with MsBuild. This parameter specifies the name of the publishing profile file to use (without the .pubxml): /p:PublishProfile=Dev

As for the other parameters we use “MsBuild Arguments”:

SNAGHTML3ad6ead

And now you have all the information you need to generate WebDeploy package from Team Foundation Build :)

Carpe Diem.

2 thoughts on “TFS: Create a WebDeploy package using Team Build

  1. Reply James Jun 19,2015 20:31

    Why do you switch to French in the middle of the article?

  2. Reply Guillaume Rouchon Jun 20,2015 07:05

    Hi James,
    Thanks for the feedback, i don’t know why i have skipped a section while translating in English but it is now fix :)

Leave a Reply

  

  

  

CAPTCHA *