Microsoft Web Deploy Tool – Sample solution for msbuild single build multiple environment deployment with environmental configuration

Following on from my earlier post about Microsoft Web Deploy tool I’ve put together a sample solution with MSBuild scripts to build and deploy a web application and a WCF service with environmental configuration, so with a single build you can deploy to multiple environments with the right configuration and no manual config changes.

Previously I couldn’t figure out how to get the environment configuration to work for WCF endpoints and certain settings, but now I’ve got that figured out I would recommend using this over the alternatives (xml transformations, build script copying).

 

Pre-requisites:

  • VS 2010 (or latest MSBuild if deploying on server)
  • Web Deploy tool (included in VS 2010, only needed for server deploy)
  • MVC3 (included in VS 2010, only needed for server deploy)

 

The project consists of a Model class library, WCF service and an MVC3 application. The Model has a service reference to the WCF service and a custom settings file, the MVC application references the Model, both the WCF service and MVC application have environment configuration, like appsettings keys, settings sections, endpoint addresses and connectionstrings (in dbproperties.config). The master build script builds the solution and creates the web deployment packages, the Deployer script checks/creates the target host web site in IIS, substitutes the correct environment configuration into the package and deploys.

Web

Important files in the project are:

  • Parameters.xml – In both web applications, contains the list of environment configuration settings for each app, with a description and instructions for the deployer on how to find/set them (either xpath or simple match substitution)
  • SrcConfig{env}Kainos.WebBRIC.{app}.SetParameters.xml – Environmental settings used in deployment for app, contains the value to be used for each parameter in Parameters.xml and the target Virtual Directory (deployer will create if does not exist)
  • Master.build – Builds the deployment packages (ln38)
  • Deployer.build – Checks/Creates host website (using MSBuild Extension Package tasks) for IIS6 or IIS7, copies target environment configuration to package and deploys

Parameters
Setparameters

You can use the MSBuild Extension Package tasks to do a lot more than I’ve got in the sample, create host headers/app pools and setup the website correctly, but I think in the majority of cases the web site will already exist with correct configuration so this may be redundant. One thing people using the deploy tool need to be aware of is it will delete all files/folders in the existing virtual directory folder which don’t exist in the package, so they will need to backup any log files etc. if they want to keep them after a re-deployment.

Attached zipped solution embedded into word doc, as Posterous will not accept zips.

Advertisements

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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s