C# .NET web.config transformations or not?
13 Apr 2011At work the other day, we had an issue regarding reporting services. We have two servers, one is the test and one is the live server.
The requirement was:
- When debugging the web application, point to the test Reporthost
- When running in ‘Release’, point to the live Reporthost
We figured that we could use web.config transformations – that is, two different web.config files for the two solution configurations: Web.Config, Web.Debug.Config, and Web.Release.config.
Unfortunately, we found that this wouldn’t work after a lot of research and trial and error – it only works when the project is published (deployed).
Refusing to be beaten by Visual Studio, we decided to use the Build Event feature, and for whatever solution configuration the project was currently set to, we would search the specified files and replace the text (i.e. From TestReporthost to LiveReporthost). We shortly realized that we would need a third party tool to help with this, and that was the FART tool (http://fart-it.sourceforge.net/).
The prebuild event:
if $(ConfigurationName) == Debug ( $(SolutionDir)debug.bat ) ELSE ( $(SolutionDir)release.bat )
The bat file(s):
X:\App\fart.exe -i <pathtofile> <find> <replace> EXIT 0
Everything worked beautifully, and the requirements were met.
Tags: .NET, ASP, ASP .NET, c++, Reporthost, Reporting Services, Server, transform, Visual Studio 2010, web.config