VB.NET Forms 应用程序中.exe.config 文件的预期用途
我目前正在阅读有关我可能会被分配的任务的文档。在设计文档中,他们讨论了 .exe.config 文件。他们声明其唯一目的是存储常量:
“另请注意,该文件仅用于存储常量,并不意味着将配置值写入(并且 .NET 1.1. 框架甚至通过不提供类/方法来执行此操作)。因此,配置是使用...“
据我了解,这是不正确的。我不知道 .NET 1.1 是否会阻止这种情况,但我记得在我的上一个项目中,我确实将配置值写入了该文件(我在那里保存了 GUI 内容)。我的项目是一个小型原型,所以也许我做错了,但我不这么认为......
那么这个文件的预期目的是什么?
提前致谢。
I am currently reading up on documentation for a possible assignment I might be put on. In a design document they talk about the .exe.config file. They state that its only purpose is to store constants:
"Also note that this file is meant to store constants only, it is not meant to write configuration values to (and the .NET 1.1. framework even prevents this by not offering classes/methods to do so). Therefore, configuration is written to XML files using a..."
As far as I understand, this is not true. I don't know about .NET 1.1 preventing this, but I remember in my last project that I did write configuration values to that file (I saved GUI contents there). My project was a small prototype, so maybe I did it wrong, but I do not think so...
So what is the intended purpose of this file?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,这是准确的。请注意设置设计器中的范围列。 “应用程序”用于设置进入 app.exe.config 的值。 “用户”应用于可以修改和保存的设置。它们位于一个名为 user.config 的单独文件中,该文件存储在 AppData 的子目录中。
它需要以这种方式工作,因为您通常需要管理员权限才能修改 app.exe.config 文件。它必须与 EXE 存储在同一目录中。对于受限用户帐户或打开 UAC 的管理员帐户,正常安装位置 (c:\program files\something) 是只读的。
No, that's accurate. Note the Scope column in the Setting Designer. "Application" is used for setting values that go into app.exe.config. "User" should be used for settings that can be modified and saved back. They go in a separate file named user.config which is stored in a subdirectory of AppData.
It needs to work this way because you normally need admin privileges to modify the app.exe.config file. It must be stored in the same directory as the EXE. The normal install location (c:\program files\something) is read-only for restricted user accounts or admin accounts with UAC turned on.
虽然您可以编辑配置文件的内容,但这通常不是一个好主意。该文件用于配置信息,而不是配置文件/设置信息。 .NET 2+ 中还有其他用于该类型数据的 API
While you can edit the contents of the config file, it's not generally a good idea to do so. That file is for configuration information, as opposed to profile/settings information. There are other APIs for that type of data in .NET 2+
您将设置存储在那里。这是一个广泛的概念,很多东西都可以考虑设置。常量、连接字符串、凭据甚至 GUI 布局。实际上任何 XML 数据。
You store settings there. This is a wide concept, a lot of things can be considered settings. Constants, connection strings, credentials and even GUI layout. Any XML data actually.