c# – user.config文件没有被创建但是app.config是?

c# – user.config文件没有被创建但是app.config是?,第1张

概述我的程序内置了一些设置,其中都有一个用户范围.但是,当程序启动时,它只会创建包含设置的AppName.exe.config文件. 在运行时期间稍后保存设置时,它会在AppData / Local / AppName / location中创建user.config文件(以前不存在),但该文件仅包含已保存的设置. 为什么会这样?为什么不创建user.config或在启动时使用它? 从 Applica 我的程序内置了一些设置,其中都有一个用户范围.但是,当程序启动时,它只会创建包含设置的Appname.exe.config文件.

在运行时期间稍后保存设置时,它会在AppData / Local / Appname / location中创建user.config文件(以前不存在),但该文件仅包含已保存的设置.

为什么会这样?为什么不创建user.config或在启动时使用它?

解决方法 从 Application Settings Architecture at MSDN开始:

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文件已创建.

简而言之,只要用户范围设置与每个人相同(默认值),就不需要每用户user.config文件.

总结

以上是内存溢出为你收集整理的c# – user.config文件没有被创建但是app.config是?全部内容,希望文章能够帮你解决c# – user.config文件没有被创建但是app.config是?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1243268.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存