Moving a custom configuration group to a separate file

前端 未结 1 1121
悲哀的现实
悲哀的现实 2020-12-05 14:05

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:



        
相关标签:
1条回答
  • 2020-12-05 14:55

    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

    0 讨论(0)
提交回复
热议问题