2009-10-13 4 views
18

최근에 커다란 사용자 지정 구성 그룹을 작성했습니다.사용자 지정 구성 그룹을 별도의 파일로 이동

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

이것은 당신이 appSettings는 대한 파일 속성과 함께 할 수있는 것과 유사한 무언가이다 : 다음을 통해 별도의 파일에이 구성을 이동 할 수 있을지 궁금합니다. 내 custom 섹션 핸들러에 대한 ConfigurationPropertyAttribute를 만들 필요가 있다는 것을 알았지 만, 이와 관련하여 예제 나 방향을 찾지 못했습니다.

답변

27

지금까지 내가 아는 한, 당신은 는 전체 SectionGroup (즉 MyCustomGroup)을 configSource 속성을 사용하여 구체화 할 수는 없지만 제 레벨 (즉, MyCustomSection)

<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> 

마크

+1

매력처럼 작동합니다. –

+1

정확합니다. 섹션 그룹은 전체적으로 외부화 될 수 없지만 해당 섹션은 할 수 있습니다. –

+0

@marc_s - 위대한 질문이었습니다. 나는 단지 인터넷 검색이었고 이것을 최고 결과로 발견했다! – Liath