【发布时间】:2013-08-15 13:11:51
【问题描述】:
我正在尝试使用 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 变换的新手,所以可能漏掉了一些明显的东西。
【问题讨论】:
标签: xml nuget web-config-transform xdt-transform