如果删除*.exe.config会发生什么?
我将应用程序设置添加到项目中。这些设置保存在“NameOfMyApp.exe.config”中。如果有人删除这个文件会发生什么?是否需要重新创建?我应该在哪里存储默认设置的值?
I added application settings to the project. These settings are saved in 'NameOfMyApp.exe.config'. What would happen if somebody were to delete this file? Is it necessary to create it again? Where should I store the values of default settings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用设置设计器和生成的代码(在 Properties 命名空间中),则(生成的)代码中有默认值。
If you are using the settings designer and the generated code (in the Properties namespace) you have defaults in the (generated) code.
如果有人删除了 .config 文件,它就消失了,宝贝,消失了。并且需要再次创建、部署或获取它。
存储默认设置的值 - 可能两个明显的答案是在配置文件或数据库表中。如果您的默认设置相当静态并且并非真正特定于用户,则配置文件可能是一个不错的选择(或在初始部署/安装时设置)。如果用户可以更改这些值,则最好将它们存储在数据库中。
我认为存储默认设置的位置的答案实际上取决于应用程序的性质以及用户如何使用它。
希望这有帮助!
更新:哦,如果他们确实删除了配置,我希望您将其存储在源代码管理中的某个地方。 :) 可能会让你的生活变得更轻松。祝你好运!!
If someone deletes the .config file, it's gone, baby, gone. And it will be necessary to create, deploy, or GET it again.
Storing values of default settings - probably two obvious answers would be in a config file or a database table. If you default settings are fairly static and not really user specific, a config file may be a good option (or are set at the initial deployment/installation). If these values can change by the user, it's probably better to store them in the database.
I think the answer to where to store your default settings really depends on the nature of the application and how the user's use it.
Hope this helps!
UPDATE: oh, and if they do delete the config, I hope you have it stored in source control somewhere. :) Probably make your life a lot easier. Good luck!!
如果生成的代码中有 global::System.Configuration.DefaultSettingValueAttribute ,程序将正常工作。
我编写了简单的示例(Windows 窗体):
TbText 范围是应用程序。我以发布模式编译它。我删除了除 *.exe 之外的所有文件。它工作正常,因为此设置已进入汇编:
Program will be work correctly if there is global::System.Configuration.DefaultSettingValueAttribute in generated code.
I wrote simple example (Windows Forms):
TbText scope is application. I compiled it in release mode. I deleted all files except *.exe. It is work correct because this setting is into assembly: