gpt4 book ai didi

xml - 当目标配置文件的结构未知时如何处理深度 XDT 转换?

转载 作者:数据小太阳 更新时间:2023-10-29 02:30:49 28 4
gpt4 key购买 nike

我正在尝试使用 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 /> 部分),这会导致错误:

No element in the source document matches '/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 转换的新手,所以可能错过了一些明显的东西。

最佳答案

看起来像this will do the trick .

VS2012 中的新功能,xdt:Transform="InsertIfMissing"

关于xml - 当目标配置文件的结构未知时如何处理深度 XDT 转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18217236/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com