开发者

What overwrites the <executble-name>.exe.config file with the original App.config at the end of debugging?

开发者 https://www.devze.com 2023-02-19 15:47 出处:网络
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?

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 key开发者_JS百科s.

           // 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消