c# - 如何从不同的项目访问/修改应用程序的配置文件?
问题描述
我在名为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 的路径,但实际上这个文件夹根本不存在。
我的问题是我想访问我机器上存在的实际配置文件。我怎样才能做到这一点?
解决方案
推荐阅读
- typescript - Typescript - 具有通用属性的自我引用
- javascript - 转账时拆分ETH
- r - Bacondecomp 如何处理缺失值
- python - 写入现有 CSV 文件并保存其数据
- android - Android:特定行数的芯片
- functional-programming - 伊莎贝尔结构证明
- vb.net - 如何基于另一个按钮引用一个按钮
- css - Scrapy / xpath 不起作用 - 仅适用于 css
- python - Python 在不同环境中比较 int(Docker 与本地机器)
- google-cloud-platform - 资源不足 - Google Cloud