.net 如何使用配置转换删除环境变量

.net 如何使用配置转换删除环境变量,.net,xml,visual-studio,web-config,web.config-transform,.net,Xml,Visual Studio,Web Config,Web.config Transform,我有web.config和这两个需要删除的环境变量,请参见下面的web.config web.config <aspNetCore processPath=".\Widgets.API.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess"> <environmentVariables> <environm

我有web.config和这两个需要删除的环境变量,请参见下面的web.config

web.config
      <aspNetCore processPath=".\Widgets.API.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
        <environmentVariables>
          <environmentVariable name="COMPLUS_ForceENC" value="1" />
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
          <environmentVariable name="CORECLR_ENABLE_PROFILING" value="1" />
web.config
我正在尝试使用

web.Release.config

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <location>
    <system.webServer>
      <aspNetCore>
        <!--remove the environment vars section in Release mode-->
        <!--
        Why? Because .NET Core has a bug where it adds environmentVariables section
        during the build with the environment set as Development..  
        This obviously fails in production, which is why we remove it during 
        release.
      -->
        <environmentVariable name="COMPLUS_ForceENC" value="1"  xdt:Transform="Remove" />
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" xdt:Transform="Remove" />
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

web.Release.config

无法使用模式“web.Release.config”转换文件“D:\Octopus\Applications\Widgets\XW QA\WidgetsAPI\2019.9.5_2\web.config”。

使用下面的命令,我可以解决此问题

        <environmentVariables>
          <environmentVariable name="COMPLUS_ForceENC" value="1" xdt:Transform="Remove" xdt:Locator="Match(name)"/>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" xdt:Transform="Remove" xdt:Locator="Match(name)"/>
        </environmentVariables>


Tip:在当今CI+CD时代,最好根本不使用配置转换,将静态配置文件放在单独的SCM repo中,并将其部署到适当的环境中。配置文件不应该受“构建”的摆布。尽管出于某种原因,我收到了以下警告:警告:源文档中没有与“/configuration/system.webServer/aspNetCore/environmentVariables/environmentVariable[@name='COMPLUS_ForceENC']”匹配的元素