Saturday, June 29

ProjectConfigTransformFileName - Web.Config Transformation

The Need
We start to use AppHarbor .NET PaaS to deploy our web-application.
Because we still have another instance of the same application running in shared hosting provider we needed a way to support both deployment from the same code-base.

The Problem
Visual Studio support different configuration for project out-of-the-box. The two default configurations are Debug and Release. In web projects you also have a matching web.config transformation file for each configuration, that is web.debug.config and web.release.config. Each of them contain only the parts that need to change for each configuration.
I want to have a third web.config transformation with AppHarbor specific configuration without having a new project configuration.
Visual Studio does not support this setup, but MSBuild does.

Why?
I choose not to add a new project configuration, even though it's the route Visual Studio takes you, because it will mean that our team will have one more thing to learn, one more thing to maintain and one more thing that can go wrong.

The Solution
After some digging into Microsoft.Web.Publishing.targets that is located in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web in my dev machine I found the MSBuild variable name ProjectConfigTransformFileName.
Microsoft did a great job of convention over configuration with this script. The convention is to use the web.config transformation name web.[configuration].config but if you specify ProjectConfigTransformFileName it will use that one over the convention.

Since we use Jenkins as CI server we simply pass one more parameter to the MSBuild /p:ProjectConfigTransformFileName=web.release.appharbor.config and now everything works exactly the same beside the fact we use AppHarbor web.config transformation.