C# - app config doesn't change

前端 未结 2 1520
南笙
南笙 2021-02-08 02:12

I want to save some settings on a config file for future use. I\'m trying to use the regular code that I see on all the tutorials -

 Configuration config = Conf         


        
2条回答
  •  借酒劲吻你
    2021-02-08 02:27

    When you deploy your application to your end users, there is no vshost.config.
    Your changes will be applied to the real exe.config. So you don't have to worry for this.

    When you build your application in a debug session, the app.config file, present in your project, gets copied over to the output directory. Then this config file gets copied to vshost.config as well. In this way the contents of app.config overwrites any changes made during a debug session in the vshost.exe.config.

    However let me say that writing this kind of information into an application config is a bad practice. The configuration file should be used only to store permanent configuration that usually don't change during the lifetime of your application. Connection settings, for example, are valid info to store there because you normally don't change these and you don't want to hard code them.

    Settings like the user name should use user.config instead. This config is per-user/per-app and allows read/write access.

提交回复
热议问题