如何使用XDT在web.config中查找元素,然后将其更改以进行nuget部署

问题描述

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)