Configuration Transformation (2) - App.Config - SlowCheetah

This series of articles shows how to automate the process of changing the config file when deploying an App to different destination environments.

This article shows how to automate the process of changing the App.config file when deploying an App other than Web to different destination environments.

Introduction

Visual Studio supports web.config transform files for web applications natively, but has no such functionality for Windows or other applications and their app.config files. We can, however, emulate this same behavior with a few simple steps --- with a help of Microsoft Visual Studio Plugin: SlowCheetah.

The content of this article:

  • Installation of SlowCheetah
  • Create Sustom App.Config Transformation
  • Demo for Environment Configuration Transformations

Installation of SlowCheetah

SlowCheetah is a Microsoft VS plugin that helps with creating and visualizing configuration transformations for multiple build configurations which is very helpful for Windows applications.

You can install the extension by either

  1. Go to https://marketplace.visualstudio.com/items?itemName=vscps.SlowCheetah-XMLTransforms and install the extension. Visual Studio will need to be restarted after the installation.
  2. In Visual Studio, go to
    a. (VS2019) Extensions→Manage Extensions
    b. (VS2017) Tools→Extensions and Updates...
    and search for "SlowCheetah" under Online->Visual Studio Marketplace and Download. The extension will be installed after closing Visual Studio.

Configuration Transformation (2) - App.Config - SlowCheetah

After closing all Visual Studios windows, the VSIX Installer window will pop up.

Configuration Transformation (2) - App.Config - SlowCheetah

In progress

Configuration Transformation (2) - App.Config - SlowCheetah

You will be notified when the installation is complete.

Configuration Transformation (2) - App.Config - SlowCheetah

We realize that before SlowCheetah installation, Right Click App.Config, there is no Add Transform choice.

Configuration Transformation (2) - App.Config - SlowCheetah

While after installation, we can see the Add Transform.

Configuration Transformation (2) - App.Config - SlowCheetah

Create Custom App.Config Transformation

Add a new Configuration by Configuration Manager

As we did in Configuration Transformation (1): Web.Config, Create a new dev configuration.

Configuration Transformation (2) - App.Config - SlowCheetah

for WindowsFormsApp3

Configuration Transformation (2) - App.Config - SlowCheetah

Solution file

Configuration Transformation (2) - App.Config - SlowCheetah

Project file.

Configuration Transformation (2) - App.Config - SlowCheetah

Add config transform files

Right Click App.Config => Add Transform.

Configuration Transformation (2) - App.Config - SlowCheetah

SlowCheetah will ask to install the SlowCheetah NuGet package when creating these Transform files.

Configuration Transformation (2) - App.Config - SlowCheetah

We should choose YES to accept the request. However, if we choose NO, what will happen.

Configuration Transformation (2) - App.Config - SlowCheetah

The default App.Debug.config and App.Release.config files are still added, while App.Dev.config file is not added, see the project file.

Configuration Transformation (2) - App.Config - SlowCheetah

On the other hand, if we choose YES to install the SlowCheetah NuGet package, then we can add App.dev.config file into the project.

Configuration Transformation (2) - App.Config - SlowCheetah

With project file like this.

Configuration Transformation (2) - App.Config - SlowCheetah

This will add a custom step to the Project's configuration file to execute the XML transformation at the end of the build. Evidence of this SlowCheetah package is added to the project file which can be seen from project file.

This shows the SlowCheetah package has been installed.

Configuration Transformation (2) - App.Config - SlowCheetah

This shows the SML transformation will be executed at the end of the buiild.

Configuration Transformation (2) - App.Config - SlowCheetah

Dome for Environment Configuration Transformations

Suppose we add all app.config transform files like this:

Configuration Transformation (2) - App.Config - SlowCheetah

We need to follow the procedure below to add Environment Configuration Transformations:

  • Open the base app.config file and identify all settings that are environment specific. Some typical settings that will be environment- or configuration-specific: 
    a. Internal web service or API URLs, starting with http:// or https://, or contain the name of a known web server, Big-IP/load balancer name, or web service.
    b. Internal network file server paths, starting with such as \\brutus\ or \\porcia\ or \\caesar\; or much less common, a mapped drive beginning with a letter other than C:\ or D:\.
    c. "Send to" or "cc" email addresses
    d. Database names or Oracle database aliases as found in the TNSNames.ora file.
    e. Some workflow indicators (must be evaluated for each application):
    1. Device Names or Intelligent Agent names (names ending with " IA").
    2. Task names that have a certian suffix suggesting a team number.
    3. Team numbers or Team IDs.

f. Further suggestions.

For instance, in eHeader there are these 7 environment-specific settings:

Configuration Transformation (2) - App.Config - SlowCheetah

It is very important to keep in mind that the transformations should only target and replace these specific environment settings, not to be a wholesale copy/paste of the entire app.config file.

As an example, here is how to modify the app.qat.config settings to transform the services references and the APIKEY to target the QAT environment.

Configuration Transformation (2) - App.Config - SlowCheetah

Notice, for ApplicationSettings, the xdt:Transform="Replace" attribute is used to replace the entire <value> XML node while for AppSettings keys the xdt:Transform="SetAttributes" just sets the value attribute. The xdt:Locator attribute is used to find the matching node using a particular attribute.

For more details on transformation options go to Web.config Transformation Syntax for Web Application Project Deployment | Microsoft Learn

To preview the transformation to make sure it will work correctly, take advantage of SlowCheetah's Preview Transform feature by right clicking on a transform config file:

Configuration Transformation (2) - App.Config - SlowCheetah

This will show the comparison between the base App.config and how it will look once it is transformed during the build process.

Configuration Transformation (2) - App.Config - SlowCheetah

Suggestion for Multiple Configurations within a Single Environment

Some programs may have multiple installation configuration within one environment, such as queue programs configured for different workflow departments. An alternative use of the config file transforms is to replace the entire appSettings or other department-sensitive sections within the app.config file.

This example has different file locations per environment and department and has three separate installation configurations per environment to run for different environments.

Configuration Transformation (2) - App.Config - SlowCheetah

References


Recommended Ebook

.NET Interview Questions and Answer: Practical Implementation

Download Now!
Similar Articles