当前位置:网站首页>C#之app.config、exe.config和vshost.exe.config作用区别
C#之app.config、exe.config和vshost.exe.config作用区别
2022-08-04 20:41:00 【梅里雪山GIS】
C#之app.config、exe.config和vshost.exe.config作用区别
vshost.exe.config是程序运行时的配置文本
exe.config是程序运行后会复制到vshost.exe.config
app.config是在vshost.exe.config和exe.config没有情况起作用,从app.config复制到exe.config再复制到vshost.exe.config
写配置文件都是写到exe.config文件中了,app.config不会变化。
app.config只在exe.config丢失的情况下在开发环境中重新加载app.config,vshost.exe.config和exe.config会自动创建内容跟app.config一样。
vshost.exe.config和app.config两个文件可不要,但exe.config文件不可少。
网络上有很多文章是讲app.config读写方法的,可是事实上这个文件程序就不能改变它。
public static void SaveAppSettings(string aKey, string aValue)
{
// 创建配置文件对象
string file = System.Windows.Forms.Application.ExecutablePath;
//此处修改为.vshost.exe.Config的内容
// System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(file);
if (config.AppSettings.Settings[aKey] != null)
{
// 修改
config.AppSettings.Settings[aKey].Value = aValue;
}
else
{
// 添加
AppSettingsSection ass = (AppSettingsSection)config.GetSection("appSettings");
ass.Settings.Add(aKey, aValue);
}
// 保存修改
config.Save(ConfigurationSaveMode.Modified);
// 强制重新载入配置文件的连接配置节
ConfigurationManager.RefreshSection("appSettings");
}
边栏推荐
猜你喜欢
随机推荐
Apache服务器配置多个站点
香港暂停进口俄罗斯部分地区禽肉及禽类产品
CAS :80750-24-9(脱硫生物素 NHS 酯)
web 应用开发最佳实践之一:避免大型、复杂的布局和布局抖动
AWS SES 的监控和告警
使用 Chrome 开发者工具 coverage 功能分析 web 应用的渲染阻止资源的执行分布情况
Red5搭建直播平台
win10 uwp modify picture quality compress picture
Qt Designer生成的图形可以自适应窗口的大小变化
基于Nodejs的电商管理平台的设计和实现
Apache服务器的配置[通俗易懂]
遇到MapStruct后,再也不手写PO,DTO,VO对象之间的转换了
在vs code中进行本地调试和开启本地服务器
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
基于HDF的LED驱动程序开发(2)
Web3安全风险令人生畏,应该如何应对?
二叉树的前序遍历
【C语言】指针和数组的深入理解(第三期)
简单理解 JS 事件循环
DICOM医学影像协议









