I am currently completing an application that was started by someone else. He is using the app.config for some settings, and a custom xml file for other parts. This drives me nuts, and I want to consolidate the configuration into one file.
But I am not certain wether to move everything into the app.config and throw out the custom xml file, or move everything into the other file and forget about app.config.
I can see two arguments, one for each option:
But I'm certain that there are a lot more things than I can think of right now. That's why I'm asking:
What are the advantages or disadvantages of using app.config for storing your configuration versus the 'traditional' configuration file?
App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.
By adding an application configuration file (app. config file) to a C# project, you can customize how the common language runtime locates and loads assembly files. For more information about application configuration files, see How the runtime locates assemblies (. NET Framework).
config are only required, if you have coded your application in such a way that it is explicitly dependent on it. If you have not done this, or have put error handling/default values or actions in place where it can't read the config file, one would assume your application could run without it.
config is parsed at runtime, so if you edit the web. config file, the web application will automatically load the changes in the config file. Â app. config is parsed at compile time, so if you edit the app.
The main benefit of using the app.config is that it is the default, supported way for a .NET app to store its config. Anyone using that app or inheriting it from you some day will thank you for using established standards instead of "rolling your own".
Also, the .NET framework has support for using, writing, creating, modifying the app.config file - if you go with your own scheme, you'll have to re-invent the wheel many times over.
So I would definitely recommend using app.config - it's THE way to do configuration in .NET and a widely accepted and well-supported standard.
Marc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With