I have a configuration file that is used in several projects, general.config , looks like this:
<?xml version="1.0" encoding="utf-8" ?> <appSettings> <add key="mykey1" value="myvalue1"/> <add key="mykey2" value="myvalue2"/> </appSettings>
In one of the projects, I need to override one of two settings. So the app.config this project is as follows:
<?xml version="1.0"?> <configuration> <appSettings file="general.config"> <remove key="mykey1"/> <add key="mykey1" value="anothervalue"/> <add key="mykey3" value="myvalue3"/> </appSettings> </configuration>
But remove doesn't work here. How can I override mykey1 without breaking mykey2 ? add works in this case. I can get myvalue3 from ConfigurationManager .
EDIT: general.config automatically copied to the output folder during compilation. Do not worry about the problem of the path. Currently I have received:
ConfigurationManager.AppSettings["mykey1"] //I got "myvalue1", but I want "anothervalue" here //that is, this item is "overrided", just like virtual methods in C
Danny chen
source share