在调试结束时,什么会用原始 App.config 覆盖.exe.config 文件?
在 Visual Studio 2010 中,调试结束时,什么会覆盖
Visual Studio 是这样做的吗?有什么方法可以切换此功能吗?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// ... Modify configuration.AppSettings.Settings by
// running Add/Remove on a couple of keys.
// Write out the <executable-name>.exe.config file...
configuration.Save(ConfigurationSaveMode.Modified);
// Break here and notice that the file has been written to.
ConfigurationManager.RefreshSection("appSettings");
}
示例 - 在退出时写出设置
请注意,我在 _FormClosing
处理程序方法末尾处中断。
In Visual Studio 2010 what overwrites the <executable-name>.exe.config and replaces it with the App.config version of the file when debugging ends?
Is it Visual Studio doing that? Is there any way of toggling this functionality?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// ... Modify configuration.AppSettings.Settings by
// running Add/Remove on a couple of keys.
// Write out the <executable-name>.exe.config file...
configuration.Save(ConfigurationSaveMode.Modified);
// Break here and notice that the file has been written to.
ConfigurationManager.RefreshSection("appSettings");
}
Example - Writing out settings on exit
Notice where I break at the end of the _FormClosing
handler method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Save() 方法仅保存作用域为用户的设置,而不保存应用程序。这些设置值将写入存储在 c:\users\name\appdata 子目录中的 user.config 文件。很难找到,子目录名称是基于应用程序名称和版本的哈希值。
这就是它必须工作的方式,程序在部署后通常没有对 app.exe.config 文件的写访问权限。 UAC 阻止程序写入 c:\program files 中的文件。
换句话说,您的 app.exe.config 不应更改。用记事本查看一下以验证这一点。
The Save() method only saves settings whose Scope is user, not Application. Those setting values get written to a user.config file that's stored in a subdirectory of c:\users\name\appdata. It is hard to find, the subdirectory name is a hash based on the application name and version.
Which is the way it has to work, a program doesn't normally have write access to the app.exe.config file after it got deployed. UAC prevents a program from writing to files in c:\program files.
In other words, your app.exe.config is not supposed to change. Look at it with notepad to verify that.