I'm working on a huge C# codebase (~300 KLOC). The components of the system use config files scattered across the folder hierarchy. Values that are read from config in one place are stored in a constant in another. There are several copies of the same config in different folders, copied and checked in once, and then never updated. Some files have 3 different versions, one for the developer machine, one for staging and another one for the live system. I have to clean up this horrible mess. How should I start? What is an intelligent strategy to deal with duplicated values in different files, multiple copies of the same file and multiple versions for different build environments? How can I store everything in one place without creating a "dependency magnet"?
Asked
Active
Viewed 1,528 times
2 Answers
3
The clean up is going be painful; you'll have to do a lot of find/replace as you move along. I'd start by leveraging what .NET already offers, which is, put all these settings on Application.config
(or Web.config
if an ASP.NET app) and use ConfigurationManager.AppSettings["key"]
to retrieve the various values. As far as the different environments, there's also support for this out of the box, you can use appSettings transformations

Icarus
- 63,293
- 14
- 100
- 115
2
The answer to your prayers is ConfigGen. Check it out on CodePlex: ConfigGen
It does exactly what you are asking for.
Update: Look at my examples of usage here: How to select different app.config for several build configurations

Community
- 1
- 1

Daniel Dyson
- 13,192
- 6
- 42
- 73