如何以包括.net中的配置文件 [英] How to include a config file for .Net

查看:118
本文介绍了如何以包括.net中的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让主.NET配置文件的app.config / web.config中包括其他配置文件?我有一个需要不断的东西在不同的文件中,但它们连接起来。

下面是什么,我想有一个例子:

 < XML版本=1.0编码=UTF-8&GT?;
<结构>
  < configSections>
    < sectionGroup名=的applicationSettingsTYPE =System.Configuration.ApplicationSettingsGroup,系统,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089>
      <节名称=LocationSearch.Properties.SettingsTYPE =System.Configuration.ClientSettingsSection,系统,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089requirePermission =FALSE/>
    < / sectionGroup>
  < / configSections>
  <的applicationSettings>
    < LocationSearch.Properties.Settings>
        <设定名=MapQuestApiKeyserializeAs =字符串>
        <价值>一些价值在这里...< /值GT;
        < /设置>
        <设定名=MapQuestClient codeserializeAs =字符串>
        <价值>此处的另一个值...< /值GT;
        < /设置>
    < /LocationSearch.Properties.Settings>
  < /的applicationSettings>
< /结构>
 

解决方案

是的,你可以包括单独的文件到使用configSource属性,像这样主要的.config:

 < securityConfiguration configSource =SomeOtherConfigFile.config/>
 

你有这样

外部配置文件必须是主要的config文件的同一目录(或子文件夹)中。

<一个href="http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx">SectionInformation.ConfigSource物业

Is there a way to have the main .net configuration file app.config/web.config include another configuration file? I have a need to keep things in separate files, but link them together.

Here is a sample of what I want to include:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="LocationSearch.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <applicationSettings>
    <LocationSearch.Properties.Settings>
        <setting name="MapQuestApiKey" serializeAs="String">
        <value>some value here...</value>
        </setting>
        <setting name="MapQuestClientCode" serializeAs="String">
        <value>another value here...</value>
        </setting>
    </LocationSearch.Properties.Settings>
  </applicationSettings>
</configuration>

解决方案

Yep, you can include separate files into the main .config using the configSource attribute like so:

<securityConfiguration configSource="SomeOtherConfigFile.config" />

External config files that you include this way must be within the same directory (or a subfolder) of the main .config file.

SectionInformation.ConfigSource Property

这篇关于如何以包括.net中的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆