Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

configuration - How to include a config file for .Net

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, with the 'file' attribute

<appSettings file="configFiles/otherConfigFile.config">

MSDN info

Some relevant information from the MSDN article about using the 'file' attribute:

The contents of the separate file are merged with the appSettings section in the Web.config file. This functionality is limited to the appSettings attribute.

Note: In the .NET Framework version 2.0, you can now include configuration settings in a separate file for all configuration elements that support the configSource attribute. However, when you use the configSource attribute, you must move the entire section to the separate file because there is no merging of element settings.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...