C# - app config doesn't change

前端 未结 2 1524
南笙
南笙 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.

    0 讨论(0)
  • 2021-02-08 02:31

    To test using the normal exe's config file un-check the box for "Enable the Visual Studio Hosting Process" in the "Debug" tab in the project properties menu. That will make visual studio no-longer use the vshost.exe file to launch and the correct config file will be used.

    enter image description here

    0 讨论(0)
提交回复
热议问题