A co-worker of mine came across a blog post about using external configuration files: http://blog.andreloker.de/post/2008/06/Keep-your-config-clean-with-external-config-files.aspx.
I realized that this can be incredibly useful, as we have had issues with config files at my current job. Currently, we are managing four different configuration files: one for development, integration, staging and production. Each of these config files have almost the exact same content, but differ in just a few ways. I anticipate just having one main config file, but keeping a set of four external config files for those pieces of the configuration files that change. We'll see how it goes.
I did a little experiment using these external config files on a "Cleanup" console app that I was working on. I followed the example of the mentioned blog post, but ran into a couple blocks.
One error I got stated that 'The attribute 'configSource' cannot be specified because its name starts with the reserved prefix 'config'.' This happened because I was trying to specify a configSource for the System.ServiceModel section of my app.config. I was trying to do this because of the fact that the URL's to WCF services in the client section might change. It turns out that you can only specify a configSource for the child elements of the System.ServiceModel section. So I changed the section that had a configSource to the 'client' element, and it fixed it.
Once I got that fixed, I ran into another issue stating 'Unable to open configSource file <Config File Name>.', which I had obviously created. I couldn't figure out why this was happening, but then I realized that the application, due to the fact that it was an executable, was looking in the BIN/Debug folder, not the root of my application. To remedy this, I made the custom .config files so they would 'Copy Always,' and then my app worked! You can refer to the screen shot below:
2 comments:
I want to thank you so much for this solution. I have spent HOURS on this and searched all over. This little gem (copy always) in the properties of the config source file is not mentioned anywhere else as far as I have found.
Keep up the good work
You just saved me some head-to-wall-hitting :) Thanks a lot!
Post a Comment