我需要使用 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 是否存在于文件中的任何位置并在那里添加我的代码?