简体   繁体   中英

Change app.config value of other project at runtime

I have two projects under the same solution. I want to change the value of a project's app.config but I don' know how to do it

Project A

Project B

They are supposed to run as such : Project A is a codedUITest, and I want to change a value of it's configuration file.

This is how I have tried

string abc = @"absolutePath\app.config";
Configuration configuration =                     ConfigurationManager.OpenExeConfiguration(abc);
configuration.AppSettings.Settings["areaCode"].Value = "new";
configuration.Save();
ConfigurationManager.RefreshSection("appSettings");

The project's app.config that I want to modify is a .dll (codedUiTestProject)

This is my node's structure :

<appSettings>
    <add key="LogFilePath" value="" />
    <add key="areaCode" value="steamAccessDummy"/>
</appSettings>

I need some help, thanks ! Are there any other solutions ?

您是否尝试过configuration.Save(ConfigurationSaveMode.Full, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM