At Lightbox we use an excellent program called FinalBuilder for automating all of our builds, and managing the configuration for the various environments we build to (system test, user acceptance testing, production etc.) It’s a very powerful tool and our “scripts” allow us to produce and deploy a build from a particular branch/tag in Subversion, targeting a particular configuration, with the touch of a button.
Once you get used to putting the projects together, using FinalBuilder is a huge time saver. One of the features it gives you is the ability to substitute “tags” in a file with the corresponding value from a project variable; so for example you could substitute %ServerName% for the variable called ServerName in the project. While this is very useful, it does require several steps to set it up each variable:
- Create the configuration file (or template) containing the %VARIABLE% tag.
- Add the corresponding variable name to an INI file (FinalBuilder had native support for INI files).
- Add the variable to the project.
- Configure the project to load that variable from the INI file.
- Add the build command to do the substitution (obviously you will usually do this once for all the variables).
While none of those tasks are particularly onerous, it is quite error prone when you are relying on your developers to perform each task, and does make writing “generic” scripts quite tricky. You may not even want your developers meddling with your build process in the first place!
As an attempt to get the same level of functionality as the FinalBuilder substitution, but without the extra steps, I put together a small utility that takes an input file, a “substitute” file to be processed and a series of “sections” to use to perform the replacement. So for example, if you had the following INI file:
[MAIN] SVNServer=MySvnServer SVNPort=80 [INT] Server=IntServer Username=IntUser Password=Password [SYS] Server=SysServer Username=SysUser Password=Password
And a “substitute” file as follows (this obviously isn’t a configuration file, it’s purely a very basic sample ):
Subversion Server: %SVNServer%:%SVNPort% Server: %Server% Details : %Username% / %Password%
Running it through the utility and specifying the MAIN and INT sections (I generally use a “global” section, then configuration specific sections) would give us:
Subversion Server: MySvnServer:80 Server: IntServer Details : IntUser / Password
So there you go, it’s a very, very simple utility, and indeed very little code; but I thought it might be of use to people who might be using FinalBuilder, or even people doing “manual” configuration management. It currently only supports INI files, but adding support for other file format is just a case of creating a new VariableReader implementation and decorating it with a ReaderHandles attribute to signify what “mode” you want it to handle.