Transform and Deployment
The first build configuration in our team city project built, tested, analyzed, and packaged our application for deployment. It created a set of artifacts that we can use to deploy this version of our application to each of the target environments.
Next we need to actually deploy our application. This process requires two steps:
- Apply config transformations
- Deploy the package
Setting up the Transform and Deploy Build Configuration
One of the first things you will notice about the transform and deploy build configuration in our Team City project is that it does not have any VCS roots. This is because it is unnecessary for these tasks to pull down the source and rebuild the application. All they need is the artifacts of the we created in our build and package build configuration. To access these artifacts, all we need to do is add them as dependencies for our configuration (steps #6):
As you can see in the image above, we need to be sure to depend on the three artifacts we created in our original build and package configuration.
Applying MSBuild Config Transformation without a Full Build
Since the artifacts necessary to deploy our application were created in the package step, it is unnecessary for us to rebuild our application. Instead we just need to modify the web.config file appropriately for the target environment. There is a very simple MSBuild target that will allow us to do this without a full build:
This target takes four inputs and uses those to transform the base web.config using the appropriate transformation:
- Source – This is the relative path to the base web.config file. We packaged this and the transformation files as artifacts of our original package build configuration. They are included and available here because they are a dependency of our build configuration.
- Transform – This is the relative path and file names of the transformations (you can see the provided $(Configuration) switch is being used to determine the correct transform file to use.
- Destination – The destination for our new configuration file once it has undergone transformation. This is the location of the package we intend to deploy.
- StackTrace – Whether or not we would like a stack trace made available.
Here is the actual MSBuild command that is run by Team City:
Once this task is completed then we have a package with the following properties:
- A fully optimized release build.
- A web.configuration file that is correct for the target of our deployment.
- Only the files and folders necessary to run this application on a hosted environment.
Now all that’s left is to deploy the application…
Deploying with MSDeploy
Our tool of choice for deploying Microsoft Web applications to IIS is MSDeploy (and I strongly recommend it to the reader). You could easily use XCOPY, ROBOCOPY, or your copy file tool of choice, but MSDeploy offers a much more robust set of features and is tailored to deploying IIS assets. For more information on MSDeploy you can go to the official MSDeploy support site.
The build configuration for this step is extremely simple: