Massage the LightSwitch web.config with web.config transformations.


Since the current Visual studio 2012 RC, it is possible to use web.config transformations. This was a feature missing in LightSwitch 2011 and also in the first beta of V2.

Why would I need web.config transformations?

Well, you don’t need web.config transformations to change the attribute values of your web.config. (e.g. changing a connectionstring between staging and production environment). For that, webdeploy has a neat parameterization system.

Nonetheless, if you want to change the shape of your web.config (e.g. adding an additional connection string because your security data are in a separate database) you will need web.config transformations.

How does web.config transformations work?

In fact, web.config transformations are not specifically a LightSwitch feature, but they are Visual studio feature (not bound to webdeploy).

You can find an excellent introduction over here:

In this post, I want to stick to a simple example.

An example

Imagine we want a second connection string in our project.

Simply update the file web.release.config as follows:

<configuration xmlns:xdt="">
    <add name="SecondConnectionString" connectionString="newstring"
       xdt:Transform="Insert" />

Change your solution configuration now to “release” and publish your project to a .zip file.

You will see that the web.config inside the .zip package looks now as follows:

    <add name="_IntrinsicData" connectionString="_IntrinsicData Placeholder" />
    <add name="SecondConnectionString" connectionString="newstring" providerName="newprovider"/>

The above example is a simple insert, but you  can do whatever transformation.


Web.config transformations are very useful when using LightSwitch in an Enterprise scenario. It allows now to cope with different configuration scenario’s and to fully automate the deployment process via TFS build server. Many thanks to the LightSwitch product team for taking the time to add this to the product.