如何在应用程序目录中创建Application.exe.config [英] How to create Application.exe.config in application directory
问题描述
因此,我最近更新了我的应用程序以支持新功能。过去,如果用户删除了配置文件,那没什么大不了的。这项新功能要求它存在,并且其中一项要求是该文件存在于应用程序的安装目录中。
So I recently updated my application to support a new feature. In the past if the configuration file was deleted by the user it wasn't a big deal. This new feature requires it to exist, and one of the requirements is that, the file exists in the application's installation directory.
我注意到删除文件时(取决于关于我尚未弄清的变量),我收到.NET通知,指出配置文件已丢失或损坏。当前,我的程序崩溃了(这仍然是我要弄清楚该行为的重复方式),这就是这个问题的原因。
I have notice when the file is deleted ( depending on variables I have not figured out ) I get a .NET notification that the configuration file is missing or corrupt. Currently my program then crashes ( I still have to figure out how to duplicate this behavior ) which is the reason for this question.
我对ConfigurationManager十分熟悉。加载默认值后,我很难写文件。出于某种原因强制执行Save似乎并没有重新创建文件,至少在安装目录中没有,这是必须的。
I am familar with ConfigurationManager. I am having trouble writting the file once the default values are loaded. Forcing a Save for some reason does not seem to recreate the file, at least not in the installation directory, which is a requirement.
我正在寻找有关如何创建文件的指导。以优雅的方式处理此角壳。我会发布代码,说实话,这只是所有失败的尝试,尽管我的尝试确实生成了文件,但内容不是我想要的设置。
I am looking for guidence on how to handle this corner case in an elegant manner. I would post code, honestly its just all failed attempts, which while my attempts do generate a file the contents are not the settings I am looking for.
我愿意
推荐答案
使用内置的配置支持停止,而只需使用写入/读取操作即可。使用标准XML类的名为something.exe.config的文件,如果该文件被删除,只需从可执行文件中的硬编码值重新创建即可。
Stop using the built-in config support and just use write/read to a file called something.exe.config using the standard XML classes and if that gets deleted, just re-create it from values hard-coded in the executable.
配置文件支持应该会使事情变得更容易,如果您需要在难以解决的地方做一些事情,请不要使用它。
The config file support is supposed to make things easier, if you need to do stuff where it makes things difficult, don't use it.
这篇关于如何在应用程序目录中创建Application.exe.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!