问题描述
我使用的是app.config文件来存储我的应用程序的动态参数。问题是,当我改变在app.config文件中的值,并启动应用程序,它不会加载从配置文件中的新价值。好像在app.config文件中的值被读取,只有在编译时嵌入exe文件!
I am using an app.config file to store the dynamic parameters of my application. The problem is, when I change a value in app.config file, and start the application, it doesn't load the new value from config file. Seems like the values in app.config file are being read and embedded in exe file only at compile time!
这是我如何读取配置文件:
This is how I read the config file:
public class Helper
{
static Helper()
{
Foo = ConfigurationManager.AppSettings["Foo"];
}
public static string Foo { get; set; }
}
我缺少的东西吗?
Am I missing something?
推荐答案
您确定要更改正确的文件?你不想改变app.config文件,但<&EXENAME GT; .exe.config
文件,在同一目录中的.exe
Are you sure you are changing the correct file? You don't want to change the app.config file, but the <exename>.exe.config
file, in the same directory as the .exe
app.config文件是在IDE编辑什么,但是当你编译你的应用程序文件重命名为<&EXENAME GT; .exe.config
,当你编译复制到输出目录。寻找默认配置时的.exe文件查找具有相同名称的文件本身具有的.config扩展。
The app.config file is what you edit in the ide, but when you compile your app this file is renamed to <exename>.exe.config
and copied to the output directory when you compile. The .exe looks for a file with the same name as itself with the .config extension when looking for the default configuration.
这篇关于重新启动应用程序后,App.config中的更改不会反映的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!