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

Dev*_*aos 5 .net xml web-config visual-studio web.config-transform

我有 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" />
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用删除这些变量

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>

Run Code Online (Sandbox Code Playgroud)

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

Dev*_*aos 5

使用下面的方法我能够解决这个问题。

        <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>

Run Code Online (Sandbox Code Playgroud)