MSDeploy - Transform configs for different teams during a local build

We have the situation where we have two teams working on the same project. Each team has it's own local database server, the connection strings are different.

On build in Visual Studio I would like the correct connectionstrings to be transformed into my /ConnectionStrings.config (it's worth noting I've pulled my connection strings into their own file which lives in the web root).


<connectionStrings configSource="ConnectionStrings.config" />

One way to do this is to create a which hooks into Afterbuild Actvity. Here is the contents of this file:

<Project xmlns="">
  <UsingTask TaskName="TransformXml"
<TransformConfiguration Condition="'$(Configuration)' == 'MyTeam'">MyTeam</TransformConfiguration>
<TransformConfiguration Condition="'$(Configuration)' == 'OtherTeam' Or '$(Configuration)' == 'Debug'">OtherTeam</TransformConfiguration></PropertyGroup>

  <Target Name="TransformConnectionStrings">
<TransformXml Condition="Exists('$(ConfigurationInput)\Configuration\Local\ConnectionStrings.$(TransformConfiguration).config')" Source="$(ConfigurationInput)\Configuration\Local\ConnectionStrings.config" Transform="$(ConfigurationInput)\Configuration\Local\ConnectionStrings.$(TransformConfiguration).config"                                                  Destination="$(ConfigurationInput)\ConnectionStrings.config" />

To run this script on build unload your website project and add this line:

<Import Project="..\Build\" />
<Target Name="BeforeBuild">

The last thing do do is create a configuration setting for each team in VisualStudio.

For a local build you would usually build with project confguration set to 'Debug'.

Open the Configuration Manager dropdown in VS and Click The Configuration Dropdown to add a Configuration.

Configuration Manager

Check to add new Project configurations and copy settings from debug.

Next to each project put each back to Debug except for your Website project.

Repeat these steps for each other team you have.

You should build using the solution configuration selected for your team.

Dave Leigh

Web, and long time Sitecore developer based in Bristol, UK, working at Valtech - - @valtech.
I occasionally do other things too.