7

Configuration file handling is a common problem so I wondered why nobody has asked a similar question yet. In .NET we usually use the app.config file for application runtime paramaters, however this seems oversized for some smaller tools. I have considered an .ini style configuration file.

Are there any other appropriate alternatives which could be easily integrated in any project?

Ant Swift
  • 20,089
  • 10
  • 38
  • 55
mbx
  • 6,292
  • 6
  • 58
  • 91
  • 1
    What exactly do you mean by oversized? You app.config file doesn't have to be huge. The file I'm looking at now contains one config section and a list of properties. – Ant Swift Oct 14 '11 at 09:07
  • I consider a typical user to change the config by hand (eg. setting an http port) for non GUI applications. – mbx Oct 14 '11 at 09:18
  • A typical user should not be setting http ports. That's an advanced user at least. – BenCr Oct 14 '11 at 09:25
  • Or a settings dialog to handle it for them. If the settings dialog is the chosen approach, the integration of app.config is wonderful. – Ant Swift Oct 14 '11 at 09:30
  • I´d like recommend Config.Net: A comprehensive easy to use and powerful .NET configuration library, fully covered with unit tests and tested in the wild on thousands of servers and applications. Found it in GitHub: https://github.com/aloneguid/config – Gabrielizalo Jul 25 '18 at 16:04
  • @Gabrielizalo [Config.Net](https://github.com/aloneguid/config) certainly looks intresting. For most of our long running services we moved to toml. yaml seems to be supported so tweaking it for toml should be feasable. OTH that part of our infrastructure is battle proven and switching is not an option. It may still come in handy for a spare time project. – mbx Jul 26 '18 at 06:43

3 Answers3

8

For desktop applications you could use application settings. And a similar post illustrating them.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
6

The best practice would be using an app.config file since support for reading it is built right into the .Net framework. I'm not sure why you think it is more oversized than other options like an ini file, at it's most basic an app.config only needs to look something like this:

<configuration>
  <appSettings>
    <add key="SomeSetting" value="foo" />
  </appSettings>
</configuration>
Dylan Smith
  • 22,069
  • 2
  • 47
  • 62
2

I would not use an own solution if you intend others to use your project. Will you always be the only developer? .NET developers are used with the existing config files.

If <appSettings> is not enough for you it's easy to create custom config sections. You can either use a visual tool like Configuration Section Designer

jgauffin
  • 99,844
  • 45
  • 235
  • 372