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
- 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.
- 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.
After closing all Visual Studios windows, the VSIX Installer window will pop up.
In progress
You will be notified when the installation is complete.
We realize that before SlowCheetah installation, Right Click App.Config, there is no Add Transform choice.
While after installation, we can see the Add Transform.
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.
for WindowsFormsApp3
Solution file
Project file.
Add config transform files
Right Click App.Config => Add Transform.
SlowCheetah will ask to install the SlowCheetah NuGet package when creating these Transform files.
We should choose YES to accept the request. However, if we choose NO, what will happen.
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.
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.
With project file like this.
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.
This shows the SML transformation will be executed at the end of the buiild.
Dome for Environment Configuration Transformations
Suppose we add all app.config transform files like this:
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):
- Device Names or Intelligent Agent names (names ending with " IA").
- Task names that have a certian suffix suggesting a team number.
- Team numbers or Team IDs.
f. Further suggestions.
For instance, in eHeader there are these 7 environment-specific settings:
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.
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:
This will show the comparison between the base App.config and how it will look once it is transformed during the build process.
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.
References