Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are best practices storing configuration settings a .NET application? [closed]

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?

like image 794
mbx Avatar asked Oct 14 '11 09:10

mbx


People also ask

Where are .NET application settings stored?

Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there.

Which file stores the configuration settings required by your application?

A configuration file, often shortened to config file, defines the parameters, options, settings and preferences applied to operating systems (OSes), infrastructure devices and applications in an IT context.

Where do you keep config files?

It's polite to put your config files not only in "Application Data" but also in a subfolder just for your software. (The application name, or your company name, etc.) TCHAR szAppData[MAX_PATH]; …

Where are C# application settings saved?

User settings are saved in a file within a subfolder of the user's local hidden application data folder.


3 Answers

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

like image 74
Darin Dimitrov Avatar answered Oct 16 '22 00:10

Darin Dimitrov


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>
like image 23
Dylan Smith Avatar answered Oct 16 '22 00:10

Dylan Smith


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

like image 30
jgauffin Avatar answered Oct 16 '22 00:10

jgauffin