在 web.config 转换的同时得到 "No element in the source document matches '/configuration/system.webServer'"

Getting "No element in the source document matches '/configuration/system.webServer'" while web.config transformation

我正在进行 web.config 转换。这是我的 web.config -

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <httpProtocol>
        <customHeaders>
            <add name="X-Content-Type-Options" value="nosniff" />
            <add name="Content-Security-Policy-Report-Only" value="frame-ancestors 'self'" />
        </customHeaders>
      </httpProtocol>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <rewrite>
        <rules>
          <rule name="https redirect">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
              <add input="{HTTPS}" pattern="off" ignoreCase="false" />
            </conditions>
            <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
          </rule>
        </rules>
        <outboundRules>
          <rule name="Remove RESPONSE_Server" >
            <match serverVariable="RESPONSE_Server" pattern=".+" />
            <action type="Rewrite" value="" />
          </rule>
          <rule name="Adding HSTS" enabled="true">
            <match serverVariable="RESPONSE_Strict_Transport_Security"
                pattern=".*" />
            <conditions>
              <add input="{HTTPS}" pattern="on" ignoreCase="true" />
            </conditions> 
            <action type="Rewrite" value="max-age=31536000" />
          </rule>
        </outboundRules> 
      </rewrite>
      <aspNetCore processPath="dotnet" arguments=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Local" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
     <system.web>
         <httpCookies httpOnlyCookies="true" requireSSL="true" />
     </system.web>
  </location>
</configuration>

我的 web.release.config 和 web.config 一样。 web.Development.config 如下所示。

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <system.webServer>
        <aspNetCore processPath="dotnet" arguments=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
            <environmentVariables>
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" xdt:Transform="Replace" xdt:Locator="Match(name)"/>
            </environmentVariables>
        </aspNetCore> 
    </system.webServer>
</configuration> 

但是当我使用“dotnet publish --configuration Development /p:EnvironmentName=Development”命令发布时,它显示 No element in the source document matches '/configuration/system.webServer' 此外,在部署到服务器时,我得到了这个 - [apply APPName_DEV\web.Development.config to APPName_DEV\web.config] W:\Buildnumber\APPName_DEV\web.Development.config:7,7 - No element in the source document matches '/configuration/system.webServer'

请帮助我,提前致谢:)

我认为您需要从基本配置中删除 <location> 或将 <location> 添加到您的开发配置中。

你正在尝试替换 <configuration><system.webServer> 但是在你的基本配置中你有 <configuration><location><system.webServer>