应用程序配置修改未反映在代码中 [英] App Config Modification not reflected in code
本文介绍了应用程序配置修改未反映在代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 appconfig 文件中有一个 appsetting 部分
I have a appsetting section in appconfig file as
<appSettings>
<add key="DayTime" value="08-20"/>
<add key="NightTime" value="20-08"/>
</appSettings>
我很想在应用程序运行时修改应用程序配置.我在应用程序运行时将键 DayTime
更改为 11-20.
I am tyring to modify the app config while application is running. I changed key DayTime
to 11-20 while application is running.
现在,如果我再次运行此代码以从配置中获取数据,它会显示之前的设置值.
Now if I run this code again to fetch data from config, it shows previous set values.
private void btnDayNightSettings_ShowingEditor(object sender, ItemCancelEventArgs e)
{
string[] strDayTime = ConfigurationManager.AppSettings["DayTime"].Split('-');
}
为什么会这样?
推荐答案
app.config
文件中的 AppSetting section
在更新过程中没有得到反映的原因运行时间如下:
The reason behind why the AppSetting section
in app.config
file is not getting reflected during update in Run time is as follows:
- 当您添加新的 app.config 文件时,它实际上会在本地系统中创建一个文件.
- 当你编译它时,它实际上会在
Debug/Release
文件夹中创建必要的文件,包括.Exe
文件;取决于构建模式. - 成功构建后,它还会生成一个
.config
文件,它看起来像YourApplicationName.exe.config
,其中包含原始 app.config 文件中的相同条目.而.Exe
总是指向这个文件. - 因此,每当您在运行时编辑
app.config
时,它实际上都会更新文件,但是YourApplicationName.exe.config
文件中的更改不会更新,因为它没有重新尚未构建.
- When you add a new app.config file it actually creates a file in the local system.
- When you compile it, actually it creates the necessary files including
.Exe
files inDebug/Release
folder; depending upon the Build mode. - After successful build it also generates a
.config
file which looks likeYourApplicationName.exe.config
which holds the same entries in original app.config file. And the.Exe
always refers to this file. - So whenever you edit the
app.config
at Runtime it actually updates the file but changes are not updated inYourApplicationName.exe.config
file as it has not re-build yet.
因此,每次您需要重新构建应用以反映更改时.
So every time you need to re-build to your app to reflect the changes.
这篇关于应用程序配置修改未反映在代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文