Tuesday, July 29, 2008

Managing Your Different Environments Using External Configuration Files

Download Example Solution: Click Here

One thing that I have found as I have worked for my current employer and worked on a large-scale web application is that configuration files can get hairy.  This has proven to be especially true as we have managed the different configurations for our different environments (development, integration, staging and production).

Our web.config files have grown to about 1000 lines, which becomes a bear when you have to make sure that 4 of those files are in sync.


External Config Files To The Rescue

Recently I stumbled upon the beauty of external configuration files, which has made me realize that I can isolate the configuration settings that change and only worry about managing those changes in each of the configuration files and not the entire set of configuration settings.

You may put all of your external configuration files in the root folder along with your web.config, but I'm warning you that this can get ugly in a hurry the more environments you have and as the sections of the configuration file you are breaking out.  I recommend making a sub-folder that will hold all of your external config files and reference them by prefixing the configSource with your sub-folder (e.g. configSource="Config\ConnectionStrings.config").  You may then use folders to organize the different types of configuration settings as well.




Keep in mind as you use external config files that you have to have a separate configuration file for each section of the configuration file that you break out.  You also can only specify an external config file at certain levels of the configuration file.  For example, you can't specify an external configuration file for the entire System.ServiceModel section of your config file.  However, you can specify an external config file at the client level under the System.ServiceModel section.



Download the example project to see how you might us these external configuration files:

Click Here

No comments: