Transform Config Using Slow Cheetah

Introduction

Here I come with an article to help my developer community. This article is about transforming your app.config/web.config settings based on the configuration environment selected using package Slow cheetah. I have also created a demo project to demonstrate how this works. Hope you find it interesting!

Background

This article is a reference.

Step by step process

Step 1: Install the package "Slow Cheetah" into your solution.



Step 2: Right click on the App.config and select the option Add Transform.



The Add Transform will add the available configuration environment app.config (like for Test the config file will be added as App.Test,Config) files under the "App.config"



Step 3: To tweak the appsetting values ,connection strings etc based on the configuration environement. Here I am tweaking the webServiceUrl value based on environment.

This is the default value in the App.config.

  1. <add key="webServiceURL" value="https://dev.com"/>  
The below setting is added into the App.Test.config. So here I am replacing the webServiceURL value to "http://test.com" when the selected configuration is Test.
  1. <add key="webServiceURL" value="http://test.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/>  
Woohooo!! All done, this is how you do the transform. Now select the configuration and run F5.

Add Configuration Environment

Here, I am just focusing on adding the configuration for a new environment. By following the below steps you can configure the environment.

Step 1: Select the configuration manager from the drop down as shown below. The configuration Manager window pops up.



Step 2: Select the option <New> from the drop down "Active Solution Configuration" to add a new environment configuration.



Step 3: Enter the environment name for which you want to add the configuration and click on OK. So here I am adding the Perf environment configuration.



That's All you have added the configuration for the environment. Now you can check whether the newly added environment is added in the list or not.



Example

To demonstrate this I have created a console application which will transform config using slow cheetah. I have followed the above steps and added the three Configuration environments "Perf","Test" and "UAT". And based on the configuration environment selected in my demo the url value gets changed.



Points of Interest

You can also preview the transformation by right clicking on the particular config file and then select the option "Preview Transform".

Like here I want to preview my test config.



So this is how the transformed config looks now.

 

Up Next
    Ebook Download
    View all
    Learn
    View all