当前位置:网站首页>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");
}
边栏推荐
- 数字IC设计中基本运算的粗略的延时估计
- Latex分章节、分段落编译:input{}与include{}的区别
- ts集成和使用
- Using Baidu EasyDL to realize forest fire early warning and identification
- About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
- After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
- 多商户商城系统功能拆解22讲-平台端分销商品
- 【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库
- STP基本配置及802.1D生成树协议的改进
- Interviewer: How is the expired key in Redis deleted?
猜你喜欢

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

【C语言】指针和数组的深入理解(第三期)

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

如何用好建造者模式

暴雨中的人
![[TypeScript] In-depth study of TypeScript enumeration](/img/27/4836e59528bb5a51ffc1cf9961c6b6.png)
[TypeScript] In-depth study of TypeScript enumeration

【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...

After the tester with 10 years of service "naked resignation" from the big factory...

Desthiobiotin衍生物Desthiobiotin-PEG4-Amine/Alkyne/Azide/DBCO

QT(42)-QT线程-线程调用槽函数
随机推荐
【SQL】触发器同步表数据
Apache服务器配置多个站点
使用百度EasyDL实现森林火灾预警识别
Web3安全风险令人生畏,应该如何应对?
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
刷题-洛谷-P1319 压缩技术
Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
微信小程序云开发 | 赠、删、改城市名称信息的应用实现
简单理解 JS 事件循环
Using Baidu EasyDL to realize forest fire early warning and identification
About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
【debug】postgres数据存储错乱
Go study notes (Part 1) Configuring the Go development environment
win10终端中如何切换磁盘
刷题-洛谷-P1304 哥德巴赫猜想
无代码平台字段设置:基础设置入门教程
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
Web3时代的战争
run command for node
搭建MyCat2双主双从的MySQL读写分离