Che*_*hen 10 .net c# configuration app-config
我有一个在几个项目中使用的配置文件general.config,看起来像:
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="mykey1" value="myvalue1"/>
<add key="mykey2" value="myvalue2"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
在其中一个项目中,我需要覆盖两个设置中的一个.所以app.config这个项目看起来像:
<?xml version="1.0"?>
<configuration>
<appSettings file="general.config">
<remove key="mykey1"/>
<add key="mykey1" value="anothervalue"/>
<add key="mykey3" value="myvalue3"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是remove不在这里工作.如何在mykey1不破坏的情况下覆盖mykey2?add适用于这种情况.我可以myvalue3从ConfigurationManager.
编辑:general.config编译时自动复制到输出文件夹.不要担心路径问题.目前我得到了:
ConfigurationManager.AppSettings["mykey1"]
//I got "myvalue1", but I want "anothervalue" here
//that is, this item is "overrided", just like virtual methods in C#
ConfigurationManager.AppSettings["mykey2"]
//this setting will not be modified, currently it works fine
ConfigurationManager.AppSettings["mykey3"] //good
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7521 次 |
| 最近记录: |