3

XDT 変換を使用して NuGet パッケージの web.config インストーラーを作成しようとしています。

web.config ファイルを変換したい:

<configuration>
    <system.web>
    </system.web>
</configuration>

次のようになります。

<configuration>
    <system.web>
        <httpHandlers>
            <add path="*." verb="*" type="CustomHandler" />
        </httpHandlers>
    </system.web>
</configuration>

私が試した変換は次のとおりです。

変換 #1:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.web>
        <httpHandlers>
            <add path="*." verb="*" type="CustomHandler" xdt:Transform="Insert" />
        </httpHandlers>
    </system.web>
</configuration>

これは、ターゲットの web.config に既に<httpHandlers />セクションが含まれている場合にのみ機能します。

上記の例 (セクションがないことに注意してください<httpHandlers />) では、エラーが発生します。

ソース ドキュメントに「/configuration/system.web/httpHandlers/add」に一致する要素がありません

変換 #2:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.web>
        <httpHandlers xdt:Transform="Insert">
            <add path="*." verb="*" type="CustomHandler" />
        </httpHandlers>
    </system.web>
</configuration>

これは上記の例で期待どおりに機能しますが、既存の<httpHandlers />セクションを含む web.config ファイルがあると、そのセクションが複製されます。

これは NuGet パッケージ用であり、ユーザーの構成の状態について推測することはできません。

私は XDT Transforms を初めて使用するので、明らかな何かを見落としている可能性があります。

4

1 に答える 1

3

これでうまくいくようです。

VS2012 の新機能xdt:Transform="InsertIfMissing"

于 2013-08-14T11:04:52.670 に答える