Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving a custom configuration group to a separate file

Tags:

I've recently wrote a rather large custom configuration group. I'm curious if it is possible to move this configuration to a separate file via the following:

<configuration>     <configSections>         <sectionGroup name="MyCustomGroup">             <section name="MyCustomSection"/>         </sectionGroup>     </configSections>     <MyCustomGroup file="alt.config" /> </configuration> 

This is something similar to what you can do with the file attribute for appSettings. I realize there is most likely a need to create a ConfigurationPropertyAttribute for my custom section handler, however I've been unsuccessful in finding any example or direction in this regard.

like image 288
Alexis Abril Avatar asked Oct 13 '09 20:10

Alexis Abril


1 Answers

As far as I know, you cannot externalize an entire SectionGroup (i.e. MyCustomGroup) using the configSource attribute, but you have to handle this on the Section level (i.e. MyCustomSection)

<configuration>     <configSections>         <sectionGroup name="MyCustomGroup">                 <section name="MyCustomSection"/>         </sectionGroup>     </configSections>     <MyCustomGroup>            <MyCustomSection configSource="externalfile.config" />     </MyCustomGroup> </configuration> 

The external file externalfile.config would then contain your actual config settings, starting directly with your own custom section tag (no leading <?xml....?> or <configuration> or anything needed):

<MyCustomSection>     ... your settings here...... </MyCustomSection> 

Marc

like image 107
marc_s Avatar answered Dec 29 '22 09:12

marc_s