对于应用程序的配置文件修改后,只有重启程序后才会生效,有没有办法不启动程序就让配置文件生效呢?
可以像下面这样调用ConfigurationManager.RefreshSection,对配置文件刷新一下。
private void button1_Click(object sender, EventArgs e)
{
ConfigurationManager.RefreshSection("appSettings");
string str = ConfigurationSettings.AppSettings["a"];
MessageBox.Show(str);
}
注意,我直接点VS的运行,试了,没有改变,这个没有效果。
但直接运行生成的EXE文件才可以。