Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use app.config to store config data?

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:

  1. Using the standard way provided by Visual Studio is easier to maintain for somebody else than me.
  2. I can validate the custom file against my own xml schema, thus outsourcing a lot of tests if the config file has all required data etc.

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?

like image 565
Treb Avatar asked Jun 25 '09 20:06

Treb


People also ask

Why do we use app config?

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.

What is the use of app config in C#?

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).

Do I need app config?

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.

What is the difference between app config and web config?

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.


1 Answers

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

like image 136
marc_s Avatar answered Oct 22 '22 13:10

marc_s