If you run unit tests in your project, then it's very likely that you'll have one or more settings that will need to change depending on which environment you're using, e.g. the build server might need to use a different setting than your local PC. Out of the box, when we work with web projects, app.configs aren't automatically transformed. To manually tell MsBuild to transform a file you'll need to use 'Microsoft.Web.Publishing.Tasks.dll'. This is where things get interesting, 'Microsoft.Web.Publishing.Tasks.dll' only gets installed with Visual Studio. Installing Visual Studio on the build server and paying for a yearly license seems overkill to get access to one assembly, this is where SlowCheeta comes in.
Over the years I've found SlowCheeta works on my local PC brilliantly, but, for whatever reason, it sometimes doesn't seem to transform my app.config magically on the build server. There is a work around for this, which I'll outline below. First, make sure you install SlowCheetha into your project using Nuget:
Next, open up your projects '.csproj'. At the bottom of the file add the bottom four lines:
<None Include="packages.config" />
<UsingTask TaskName="TransformXml" AssemblyFile="$(SolutionDir)packages\SlowCheetah.2.5.48\tools\SlowCheetah.dll" />
<TransformXml Source="app.config" Condition="Exists('app.$(Configuration).config')" Transform="app.$(Configuration).config" Destination="app.config" />
One thing that you may need to change is the version number of the SlowCheetah package that you use 2.5.48 is the latest of writing but things change.
It is also worth noting that in the image above there is a newer Micosoft.VisualStudio.SlowCheetah package as well. I havn't used this yet as the old one works, but, you might want to consider using that.If you add the script above and you have a app.release.config, when you build your project in 'release' mode, as long as the trasnforms have been set-up correctly your app.config should automatically get updated with the latests values, enjoy!
Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge