views:

27

answers:

3

I am currently reading up on documentation for a possible assignment I might be put on. In a design document they talk about the .exe.config file. They state that its only purpose is to store constants:

"Also note that this file is meant to store constants only, it is not meant to write configuration values to (and the .NET 1.1. framework even prevents this by not offering classes/methods to do so). Therefore, configuration is written to XML files using a..."

As far as I understand, this is not true. I don't know about .NET 1.1 preventing this, but I remember in my last project that I did write configuration values to that file (I saved GUI contents there). My project was a small prototype, so maybe I did it wrong, but I do not think so...

So what is the intended purpose of this file?

Thanks in advance.

A: 

You store settings there. This is a wide concept, a lot of things can be considered settings. Constants, connection strings, credentials and even GUI layout. Any XML data actually.

Andrey
+1  A: 

While you can edit the contents of the config file, it's not generally a good idea to do so. That file is for configuration information, as opposed to profile/settings information. There are other APIs for that type of data in .NET 2+

Andrew Barber
So it is not correct to for example store the contents of the GUI there so you can load them again, next time you start?
Matthijs Wessels
That is correct; those settings would apply for everyone who used the application, which is not normally what you would want. The settings API exists to save per-user settings for programs, and Visual Studio even has lots of nice binding boilerplate built in to it to make it easy. Also note that best practices vis-a-vis User Account Control should preclude editing the config file by a user.
Andrew Barber
+3  A: 

No, that's accurate. Note the Scope column in the Setting Designer. "Application" is used for setting values that go into app.exe.config. "User" should be used for settings that can be modified and saved back. They go in a separate file named user.config which is stored in a subdirectory of AppData.

It needs to work this way because you normally need admin privileges to modify the app.exe.config file. It must be stored in the same directory as the EXE. The normal install location (c:\program files\something) is read-only for restricted user accounts or admin accounts with UAC turned on.

Hans Passant
Just to add to this: The default values for User scope settings are stored in the app.config file. When used, it is first checked if the user setting has a value in the config file in the users AppData path, if not, the default is used from the main app.config file. When saving the settings from the .NET API, the user file is written to, not the app.config at the application path.
awe