在调试结束时,什么会用原始 App.config 覆盖.exe.config 文件?

发布于 2024-10-26 15:19:31 字数 742 浏览 0 评论 0原文

在 Visual Studio 2010 中,调试结束时,什么会覆盖.exe.config 并将其替换为文件的 App.config 版本?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁以何悠 2024-11-02 15:19:31

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文