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

How to remove a environment variables using config transformations

我有 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.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'.

转换文件 'D:\Octopus\Applications\Widgets\XW QA\WidgetsAPI19.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>