首页 > 解决方案 > 如何从不同的项目访问/修改应用程序的配置文件?

问题描述

我在名为Test1 (exe) 和 Test2 (Library)的解决方案中有两个项目。我正在尝试读取保存在Test1的app.config中的用户设置,这些设置最终将保存在 appdata\local<foldername>\user.config 文件中。

我调用下面的代码从Test2 项目访问这个文件

var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);                      
var sectionGroups = config.SectionGroups["userSettings"];           
var userSettings = config.GetSection(sectionGroups.Sections["Test1.Properties.Settings"].SectionInformation.SectionName) as ClientSettingsSection;

它没有抛出任何异常,但我看到它变量“config”指的是来自 appdata\local<foldername>\user.config 的路径,但实际上这个文件夹根本不存在。

我的问题是我想访问我机器上存在的实际配置文件。我怎样才能做到这一点?

标签: c#.netsettingsapp-configconfigurationmanager

解决方案


推荐阅读