当前位置:网站首页>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");
}
边栏推荐
- 关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
- vs Code 运行一个本地WEB服务器
- Debug locally and start the local server in vs code
- Elastic Search 根据匹配分和热度分排序
- KubeSphere简介,功能介绍,优势,架构说明及应用场景
- 刷题-洛谷-P1200 你的飞碟在这儿Your Ride Is Here
- QT(42)-QT线程-线程调用槽函数
- Tear down the underlying mechanism of the five JOINs of SparkSQL
- 宝塔实测-搭建中小型民宿酒店管理源码
- ts集成和使用
猜你喜欢
Using Baidu EasyDL to realize forest fire early warning and identification
多商户商城系统功能拆解22讲-平台端分销商品
How to make good use of builder mode
vscode离线安装插件方法
暴雨中的人
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
【TypeScript】深入学习TypeScript枚举
Big capital has begun to flee the crypto space?
文章复现:超分辨率网络-VDSR
明明加了唯一索引,为什么还是产生了重复数据?
随机推荐
如何使用 jMeter Parallel Controller - 并行控制器以及一些常犯的错误
Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
Getting Started with Lattice Passwords
composition-api
五分钟入门文本处理三剑客grep awk sed
腾讯云胡启明:Kubernetes云上资源的分析与优化
Latex分章节、分段落编译:input{}与include{}的区别
hash和history路由的区别
Using Baidu EasyDL to realize forest fire early warning and identification
Retrofit的使用及原理详解
The book "The Essence of Alipay Experience Design", a record of knowledge related to testing
QT(42)-QT线程-线程调用槽函数
暴雨中的人
xss课堂内容复现
如何找到某个 ABAP structure 某字段的源头来自哪个数据库表
How to train a deep learning model?
ASP.NET商贸进销存管理系统源码(带数据库文档)源码免费分享
用 Excel 爬取网络数据的四个小案例
web漏洞扫描器-awvs
动态规划_双数组字符串