Why do people consistently recommend using appConfig instead of using Settings files? (.NET)

后端 未结 7 491
谎友^
谎友^ 2021-01-30 05:30

Very often I see the answer to the question like: \"How should I store settings in my .NET app?\" is to edit the app.config file by manually adding entries to the app.config (or

7条回答
  •  礼貌的吻别
    2021-01-30 06:00

    I believe that the biggest difference between the two is that the application cannot change the values in app.config. Those values are read at runtime and there's no built-in support for writing new values to the configuration file.

    Settings files can be changed using the Save() command.

    One major problem with the built-in support for Settings files is where the settings file is stored. If you look at your APPDATA folder, you'll see that there is a folder for the name of the company, then a sub-folder with the name of the product, then a sub-folder with a semi-random name and version info.

    Whenever you release a new version, it won't locate the Setting file from the previous version because of where the Setting file is stored. There's also no way to change where the Setting file is stored.

    I used it in one project and found it much more useful to create my own AppSettings class that uses an XML file for settings. I have control over the format and location of the file.

提交回复
热议问题