【发布时间】:2020-12-08 13:31:52
【问题描述】:
我需要使用 nuget 部署我的工作并在此过程中更改 web.config。 我使用XDT添加了以下代码:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="MyModule" type="My.Module" />
</modules>
</system.webServer>
我编写了一个简单的 XDT web.config.install.xdt,如下所示:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer xdt:Transform="InsertIfMissing">
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
<system.webServer>
<modules>
<add name="MyModule" type="My.Module" xdt:Transform="InsertIfMissing" />
</modules>
</system.webServer>
</configuration>
这很好用。直到我遇到一个系统将他们的模块置于位置而不是配置之下,就像这样:
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="MyModule" type="My.Module"/>
</modules>
....
所以在这种情况下,我的 XDT 找不到路径,并在文件末尾创建了一个新元素,这会杀死该站点。 如何搜索 system.webServer 是否存在于文件中的任何位置并在那里添加我的代码?
【问题讨论】:
标签: asp.net nuget web.config-transform xdt