24

最近、かなり大きなカスタム構成グループを書きました。次の方法で、この構成を別のファイルに移動できるかどうか興味があります。

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

これは、appSettings の file 属性でできることと似ています。カスタム セクション ハンドラー用に ConfigurationPropertyAttribute を作成する必要がある可能性が高いことは認識していますが、この点に関する例や方向性を見つけることができませんでした。

4

1 に答える 1

36

私の知る限り、属性を使用してSectionGroup全体(つまり)を外部化することはできませんが、これをセクションレベル(つまり)で処理する必要があります。MyCustomGroupconfigSourceMyCustomSection

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

外部ファイルexternalfile.configには、実際の構成設定が含まれ、独自のカスタムセクションタグから直接開始されます(先頭<?xml....?><configuration>その他は必要ありません)。

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

マーク

于 2009-10-13T20:27:59.297 に答える