2009-04-13 3 views
35

Visual Studio에서 .NET 구성 파일 (app.config, web.config 등)을 편집 할 때 응용 프로그램 설정을 선택할 때 Visual Studio의 인텔리 센스를받습니다. 사용자 정의 구성 섹션을 추가하면 어떻게 사용자 정의 설정에 인텔리 센스를 사용할 수 있습니까? 이것에 대한 쉬운 대답이 틀림 없다고 확신하지만, 구글 검색이 도움이되지는 않는다..config 파일의 사용자 정의 섹션에 Intellisense 활성화

감사합니다.

답변

28

, 당신은 속성스키마을 프로젝트에 .xsd 파일을 추가하려면 .config 파일을 열고 선택할 수 있습니다 윈도우합니다 ([…] 아이콘을 클릭) : 다른 답변으로

Screenshot of Visual Studio showing where to find and change the "Schemas" property of your <code>.config</code> file

+5

+1 수용된 솔루션은 널리 실용화 된 것처럼 보이지만 스키마 변경이 표준이며 컴퓨터에서 생성 될 수있는 모든 Visual Studio 프로젝트에 유용하지 않으면이 작업을 수행하지 않아야합니다. (http://msdn.microsoft.com/ ko-kr/library/ms255821.aspx) – Paul

10

사용자 지정 설정을위한 XSD 파일을 만들어 Visual Studio 설치의 스키마 디렉터리에 복사해야합니다. 2005의 경우 다음과 같습니다. % ProgramFiles % \ Microsoft Visual Studio 8 \ XML \ Schemas

여기에 대한 정보가 있습니다. 당신이 당신의 비주얼 스튜디오 파일을 수정할 또는 Visual Studio를 폴더에 아무것도 복사하지 않는 경우 http://blogs.msdn.com/astebner/archive/2005/12/07/501466.aspx

+0

우수합니다. 감사! –

31

는 사용자 정의 구성 섹션에 대한 XML 스키마 문서를 제공 할 필요가 말한다. 일부 글로벌 디렉토리에 .xsd 스키마 파일을 추가 할 필요가 없습니다. 당신은 App.config 파일에 사용자 정의 섹션에서 직접 참조 할 수 있습니다 :

<configuration> 

    <!-- make the custom section known to .NET's configuration manager --> 
    <configSections> 
    <section name="customSection" type="..." /> 
    </configSections> 

    <!-- your custom section --> 
    <customSection xmlns="http://tempuri.org/customSection.xsd" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:noNamespaceSchemaLocation="customSection.xsd"> 
    ... 
    </customSection> 

<configuration> 

xmlns 속성은 당신이 당신의 customSection 요소 모두에 설정할 필요가 없도록, 기본 네임 스페이스를 설정하는 단지가 그 자식 요소. (단, <configuration> 요소에 xmlns 속성을 배치하지 마십시오!)가 customSection.xsd 예를 들어, 인텔리가 사용할 스키마를 포함

:

<xs:schema id="customSectionSchema" 
      targetNamespace="http://tempuri.org/customSection.xsd" 
      elementFormDefault="qualified" 
      xmlns="http://tempuri.org/customSection.xsd" 
      xmlns:mstns="http://tempuri.org/customSection.xsd" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="customSection"> 
    ... 
    </xs:element> 
</xs:schema> 
+0

section.type에 입력해야하는 TYPE은 무엇입니까? 짐작하고 거기에 "xmlns"를 넣으면 작동하지만 ... 틀렸어. –

+1

@Prisoner, 당신은 (최소한 assembly-qualified) .NET 유형 이름 à la "Namespace.Class, Assembly"를 거기에 넣어야합니다. 프레임 워크는이 유형을 인스턴스화하고 사용자 정의 구성 섹션을 구문 분석 할 때마다이 유형을 사용합니다. 미리 정의 된 섹션 핸들러 클래스 나'IConfigurationSectionHandler' 인터페이스를 구현하는 커스텀 클래스 중 하나를 선택하십시오. 더 많은 정보를 얻으려면''App.config 커스텀 섹션 핸들러 ''와 같은 것을 google하거나 [이 코드 프로젝트 기사]와 같은 주제에 대한 기사를 읽으십시오 (http://www.codeproject.com/KB/aspnet/ConfigSections .aspx) 시작하십시오. – stakx

+0

필자는 이것이 다소 늦다는 것을 알고 있지만, Configuration Manager가 사용자 정의 설정 섹션을 읽으려고 시도 할 때 런타임 문제를 일으키고,'xmlns : xsi' 속성을 인식하지 못하는 것 같습니다. 내가 고칠 수있는 걸 알고 있니? 고마워요 –

관련 문제