在运行时期间稍后保存设置时,它会在AppData / Local / AppName / location中创建user.config文件(以前不存在),但该文件仅包含已保存的设置.
为什么会这样?为什么不创建user.config或在启动时使用它?
解决方法
Application-scoped settings can be stored in either the machine.config or app.exe.config files. Machine.config is always
read-only,while app.exe.config is restricted by security
considerations to read-only for most applications.User-scoped settings can be stored in app.exe.config files,in which case they are treated as static defaults.
Non-default user-scoped settings are stored in a new file,user.config,where user is the user name of the person currently
executing the application. You can specify a default for a user-scoped
setting with DefaultSettingValueAttribute. Because user-scoped
settings often change during application execution,user.config is
always read/write.
您首先看到的是(您所谓的)您的“内置设置”存储为(Microsoft调用的)“静态默认”用户范围设置,它们存储在app.exe中(按照2).
然后,当您在运行时回写设置时,它们被视为“非默认”用户范围设置,并且它们被写入user.config(按照3),因此为什么只有这样才能看到用户.config文件已创建.