c# - 在运行时更改其他项目的 app.config 值

标签 c# config app-config

我在同一个解决方案下有两个项目。 我想更改项目的 app.config 的值,但我不知道该怎么做

项目 A

项目 B

它们应该这样运行: 项目 A 是一个编码的 UITest,我想更改它的配置文件的值。

这是我试过的方法

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

我要修改的项目的app.config是一个.dll(codedUiTestProject)

这是我的节点结构:

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

我需要一些帮助,谢谢! 还有其他解决方案吗?

最佳答案

你试过configuration.Save(ConfigurationSaveMode.Full, true);

关于c# - 在运行时更改其他项目的 app.config 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30015807/

相关文章:

c# - 如何从异常中获取 IIS 子状态代码?

c# - 将构造函数与泛型类型定义中的对应项匹配

c# - 多维关联数组 C#

php - 拉维尔 : unable to read configuration files

C# 在没有 app.config 的情况下设置探测 privatePath?

.NET - 使用类库存储 App.config

c# - 如何在 WPF 应用程序中使用 App.config 进行 log4net 配置

c# - 尝试在 C# 中使 waveout 工作时 vhost.exe 崩溃

PHP:是否有保存配置数据的正确方法?

python - 使用常规 python 脚本运行 Nose 测试