ConfigurationManager.AppSettings 使用另一个配置文件 [英] ConfigurationManager.AppSettings use another config file
本文介绍了ConfigurationManager.AppSettings 使用另一个配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的班级大约有 10 个方法.在每种方法中,我都使用 ConfigurationManager.AppSettings
从 App.config 文件中获取价值
I have about 10 methods in my class. In every method I use ConfigurationManager.AppSettings
to get value form App.config file
喜欢
_applicationPort = int.Parse(ConfigurationManager.AppSettings["ApplicationPort"]
我的问题是我想让这段代码从另一个 app.config 文件(如 AnotherPoject.exe.config)中获取 AppSettings.
My problem is that I want to make this code get AppSettings from another app.config file like AnotherPoject.exe.config.
推荐答案
您还可以设置 app.config
来读取另一个文件.像这样:
You can also set the app.config
to read another file. Something like this:
<?xml version="1.0"?>
<configuration>
<appSettings file="my\custom\file\path\external.config"/>
</configuration>
和 external.config
将包含 appSettings 部分:
and the external.config
will have the appSettings section:
<appSettings>
<add key="myKey" value="myValue" />
</appSettings>
参考这个msdn了解更多信息.
这篇关于ConfigurationManager.AppSettings 使用另一个配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文