当前位置:网站首页>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");
}
边栏推荐
- Go study notes (Part 1) Configuring the Go development environment
- Oreo domain name authorization verification system v1.0.6 public open source version website source code
- 【TypeScript】深入学习TypeScript枚举
- EasyUi常用代码
- Win10 uwp use ScaleTransform magnify an element
- win10终端中如何切换磁盘
- vs Code runs a local web server
- 长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
- 该如何训练好深度学习模型?
- idea源码无法下载
猜你喜欢

hash和history路由的区别

Using Baidu EasyDL to realize forest fire early warning and identification

Uniapp微信雪糕刺客单页小程序源码

Matlab画图2

Web3时代的战争

帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码

面试官:Redis中过期的key是怎么被删除的?

CAS :80750-24-9(脱硫生物素 NHS 酯)

使用百度EasyDL实现森林火灾预警识别

Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
随机推荐
【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库
工龄10年的测试员从大厂“裸辞”后...
密码学系列之:PEM和PKCS7,PKCS8,PKCS12
hash和history路由的区别
实现菜单拖拽排序
腾讯云胡启明:Kubernetes云上资源的分析与优化
[TypeScript] In-depth study of TypeScript enumeration
如何用好建造者模式
推荐系统_刘老师
The book "The Essence of Alipay Experience Design", a record of knowledge related to testing
如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误
多商户商城系统功能拆解22讲-平台端分销商品
无代码平台字段设置:基础设置入门教程
香港暂停进口俄罗斯部分地区禽肉及禽类产品
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
KubeSphere简介,功能介绍,优势,架构说明及应用场景
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
【debug】postgres数据存储错乱
二叉树是否对称
Using Baidu EasyDL to realize forest fire early warning and identification