In this tutorial, you will learn how to use a marketplace extension SlowCheetah to help you preview your environment powered web.config
transforms. On a recent project, I was tasked with setting up a Ci/Cd pipeline. In our setup, we were using Jenkins as the CI server. The release process I inherited involved, doing a build (not a publish) and then manually copying the files over FTP onto the production server and then running an MS-Build task to publish the files. They wanted to use this process so they could use their in-house security tool that was configured to point at the FTP folder on the server. Whenever we made a change to the server we had to hope and guess the transform worked, not ideal, but it was what it was. The security team, would also not allow us to install anything, including Visual Studio on the server. This caused another issue as we couldn't easily do the transform on the server either. When I tried to copy the same MS-Build script we developed locally onto the server, it failed. If you look within a csproj
file you will see this line:
My local build worked as expected, however, the server would fail with an error, `an assembly could not be found error. After some Googling, I tracked the issue down because of a missing file. To run MS-Build scripts you need the MS-Build assembly. This file normally gets installed with Visual Studio, so I was stuck until I found SlowCheetah. Slow Cheetah will not only allow you to preview a transform locally (very handy) it also has its own build process. This meant I could install it via Nuget and then use it to do the transform on the server, removing the need to install Visual Studio 🔥🔥🔥
Note: For reference, the build script was based on this article Using Custom Web.config Transformations in MSBUILD.
Below gives a step-by-step overview of how to set up Slow Cheeta if you have a similar need.
Step One
First, you need to pass in the configuration in your CI server:
Step Two
Next, add Slow Cheeta via Nuget into your solution. After doing this, you should have access to some files in this directory packages\SlowCheetah.x.x.x\tools
. Specifically, you will have access to this assembly SlowCheetah.Xdt.dll
Step Three
After you have the Slow Cheeta assembly installed within your project, the next step is to create/update the build script to tell the CI server to perform a transform. As all build scripts and configurations are different, I'll try to give a basic overview of the process. The first thing we did was define the name of the web.config
to transform. In the TransformXml
section, I tell the build server the location of the Slow Cheeta assembly. This assembly has the power to transform your files! As part of the build process, a temporary copy of the web.config
will be made. The transforms will be applied to this new clone and then the temp file will replace the existing web.config
. The locations of the existing web.config
and the path to the temporary web.config
are defined in the ItemGroup
section.
The TransformWebConfig
section, defines the actual meat and bones of the script. In here we grab a file called staging web.config
. staging web.config
is then copied to a temporary location, defined in TempWebConfig
. I then perform the transform using the Slow Cheeta assembly and override the original web.config
after the process has finished. Finally, we delete the temp web.config
.
After doing this, you should then be able to run your script usingthis command:
Granted this is a very long-winded process to do a simple transformation, however, sometimes the hard approach is the most educational and in some instances, the hard approach is the only way forward. Happy Coding 🤘