39

Visual Studio で .NET 構成ファイル (app.config、web.config など) を編集すると、アプリケーションの設定を選択する際に、Visual Studio の Intellisense がガイドしてくれます。カスタム構成セクションを追加した場合、カスタム設定で IntelliSense を有効にするにはどうすればよいですか? これには簡単な答えがあるに違いないと確信していますが、大雑把な Google 検索では何の助けにもなりませんでした。

ありがとう!

4

3 に答える 3

35

他の回答が言うように、カスタム構成セクションに 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配置しないでください!)xmlns<configuration>

customSection.xsdには、IntelliSense で使用されるスキーマが含まれています。次に例を示します。

<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>
于 2011-01-09T12:21:25.853 に答える
32

Visual Studio ファイルを変更したり、Visual Studio フォルダーに何かをコピーしたりしたくない場合は、.xsdファイルをプロジェクトに追加し、ファイルを開いて[プロパティ] ウィンドウで[スキーマ.config]を選択します (アイコンをクリックします)。[…]

を見つけて変更する場所を示す Visual Studio のスクリーンショット

于 2010-01-11T19:39:47.690 に答える
11

カスタム設定用の XSD ファイルを作成し、Visual Studio インストールのスキーマ ディレクトリにコピーする必要があります。2005 の場合、これは %ProgramFiles%\Microsoft Visual Studio 8\XML\Schemas です。

ここにこれに関するいくつかの情報があります。 http://blogs.msdn.com/astebner/archive/2005/12/07/501466.aspx

于 2009-04-13T02:45:50.053 に答える