In today's tutorial, you will learn how to create per environment configuration files within Sitecore CMS. You will learn how to do this, by transforming the connection string located within the App_Config folder. You will learn all of the steps needed to make the connection string value change based on the environment you are deploying to. If this sounds of use to you, read on 🔥🔥🔥

How To Transform Sitecore Configurations

When we work on a Sitecore build, a very common scenario is to allow each developer to develop to work on a local copy of Sitecore. Each developer will likely have their own database that they are working from. This set-up will allow a team to be productive, however, it comes with a challenge. Each developer will have their own unique connection string value. Whenever a developer pulls from GIT, how do you ensure their connection string value is not lost? The reverse situation is also prevalent. How to you push code without breaking the site for the team 🤔

If you are using tools like TDS for Sitecore, it is easy to share new configurations between development environments by checking files into source control. TDS will not solve the challenge of each developer needing to have his/her own database connection strings and application settings. As we work locally, using a Sitecore package won't work, so what do we do 🤔

Build Scripts

As we are building projects within Visual Studio, it is possible to hook into the Visual Studio build process. Whenever you perform a build on your solution. You can also configure the Visual Studio build agent to run custom transforms. You can do this by adding a build script directly into the AfterBuild section, within your websites .csproj file.

In this example, I'm assuming your project structure follows the standard Sitecore layout and your connection strings are defined here:

App_Config âž¡ ConnectionStrings.config

A typically Sitecore connection string should look like this:

You will obviously not want to store environment or developer-specific values here, as this will break everyone else's configuration. To solve the problem, create a unique file per environment/developer. I might create a file called ConnectionStrings.Jon.Jones.config. We can then use transforms to copy/insert this value into ConnectionStrings.config at build time

Using this approach, we can ensure a local developers set ups never breaks on pull or pushing from source control. Within MSBuild, we can access the $(USERNAME) value. In my environment, that would give me the value Jon.Jones. Using this dynamic variable, we can write a script that will automatically find the correct file to use on a per-machine basis. Clever 😊

If you don't want to differentiate by username, another option is to use PC name instead, I personally think the Windows username is good enough, in most circumstances, so I'm sticking with it 😊

To make this work, you need to create a MsBuild script. You need to add the below configuration into your websites .csproj file, right at the bottom. Usually, if you open a Sitecore websites .csproj in notepad and scroll down to the bottom, you can see a commented out section like this:

Add the below configuration, underneath this commented out section:

In the first line, MsBuid creates a temporary version of ConnectionStrings.config called Temp.ConnectionStrings.config within the obj folder in your sites webroot. MsBuild then searches for a configuration file based on the logged-in username. If a file exists, it transforms the values into the newly created Temp.ConnectionStrings.config file. If the Temp.ConnectionStrings.config and the original ConnectionStrings.config is different, the script overrides ConnectionStrings.config with Temp.ConnectionStrings.config.

You can now check in all your team's config files and whenever anyone builds the solution, they will use their settings. Even if someone overrides connectionstring.config with their settings by accident and checks the files into source control it does not matter. On build, the problem will correct itself 😊


You now know how to deal with different developer configuration files in your Sitecore project. Every project/company will have a different build process, so, how you set this up will probably need a little bit of tweaking. The MsBuild snippet supplied should work for most teams. Happy Coding 🤘