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");
}
C#之app.config、exe.config和vshost.exe.config作用区别的更多相关文章
- app.config *.exe.config 和*.vshost.exe.config基础学习
一.问题描述 在使用config文件来保存一些参数,便于下次启动程序时自动加载上次设置的参数的功能时, 碰到个问题,vs2010下调试运行程序始终无法实现config记录上次参数值,而直接运行exe程 ...
- Debug目录、Release目录,bin目录、obj目录,vshost.exe.config文件、.exe.config文件分析【C#】
原文地址:http://blog.csdn.net/itwit/article/details/6803338 今天写程序的时候,需要更改.exe.config文件中的引用的webservice地址, ...
- 宿主进程 [*.vshost.exe] & [*.vshost.exe.config]
宿主进程 [*.vshost.exe] & [*.vshost.exe.config] pdb文件: 英文全称:Program Database File 中文全称:程序数据库 文件 Debu ...
- redis启动错误: Warning: no config file specified, using the default config. In order to specify a config
redis启动错误: Warning: no config file specified, using the default config. In order to specify a config ...
- Visual Studio 不生成.vshost.exe和.pdb文件的方法【转】
Visual Studio 不生成.vshost.exe和.pdb文件的方法[转] 使用Visual Studio编译工程时,默认设置下,即使选择了「Release」时也会生成扩展名为「.vshost ...
- [C#]Hosting Process (vshost.exe)
写在前面 最近在群里,有朋友问起这个vshost.exe进程到底是什么?当时确实不知道是个什么东东,给人的感觉是,经常看到它,就是在启动一个项目的时候,经常看到它,就是没细研究它是啥玩意儿.既然遇到了 ...
- Visual Studio 不生成.vshost.exe和.pdb文件的方法
使用Visual Studio编译工程时,默认设置下,即使选择了「Release」时也会生成扩展名为「.vshost.exe」和「.pdb」的文件. 一.先解释一下各个文件的作用: .pdb文件: 程 ...
- 宿主进程 vshost.exe
Hosting Process (vshost.exe) 宿主进程是VS的一个特性.可以提高调试的性能,可以进行部分信任调试(partial trust debugging),可以进行设计时表达式计算 ...
- [转]C# 中的.pdb/ .vshost.exe/ .vshost.exe.manifest文件讨论
原文出处:http://blog.163.com/chwei_sunshine/blog/static/19412628320125893656652/ pdb文件: 英文全称:Program Dat ...
随机推荐
- kudu记录-kudu原理
1.kudu是什么? 2.kudu基本概念 特点: High availability(高可用性).Tablet server 和 Master 使用 Raft Consensus Algorith ...
- CM记录-Hadoop运维管理
1.自动化运维--cloudera manager 2.手动运维 a.启动./start.all.sh,停止./stop-all.sh b.hdfs启动/停止:./start-dfs.sh ./s ...
- axios - 基于 Promise 的 HTTP 异步请求库
axios 是基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用.Vue 更新到2.0之后,作者就宣告不再对 vue-resource 模块更新,而是推荐使用 a ...
- offset[Parent/Width/Height/Top/Left] 、 client[Width/Height/Top/Left] 、 Element.getBoundingClientRect()
开篇提示:以下内容都经个人测试,参考API文档总结,但还是不能保证完全正确,若有错误,还请留言指出___________________________________________________ ...
- ASP.NET MVC中的Session设置
最近在ASP.NET MVC项目中碰到这样的情况:在一个controller中设置了Session,但在另一个controller的构造函数中无法获取该Session,会报"System.N ...
- VMware workstation 网络选择 NAT模式 访问外网
多年不用本地做测试 尽然被 nat 模式給卡着了 :动手的还是所以要记录一下: 1.根据自己需求创建 虚拟机 之后: 配置[网络适配器] -- 选择 nat 模式 ( 选择网卡 ) 虚拟机 ...
- Flask最强攻略 - 跟DragonFire学Flask - 第四篇 Flask 中的模板语言 Jinja2 及 render_template 的深度用法
是时候开始写个前端了,Flask中默认的模板语言是Jinja2 现在我们来一步一步的学习一下 Jinja2 捎带手把 render_template 中留下的疑问解决一下 首先我们要在后端定义几个字符 ...
- J - Joseph and Tests Gym - 102020J (二分+线段树)
题目链接:https://cn.vjudge.net/contest/283920#problem/J 题目大意:首先给你n个门的高度,然后q次询问,每一次询问包括两种操作,第一种操作是将当前的门的高 ...
- python - 添加文件环境变量
#添加 当前文件目录 import sys,os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) sys.path.append(BASE ...
- Kali2.0更新
下载链接:猛戳这里 更新以后速度与界面友好性提高了! 界面仿造了ubuntu和fedora,应用也有很多小图标!这个对个人来说比较赞 安装以后的几件事 1.安装vmtools,方法跟1.0一样! ta ...