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

标签 .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>
          <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\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>

关于.net - 如何使用配置转换删除环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57813119/

相关文章:

c# - Bitmap.Save 在几个小时后停止工作

c# - 我可以避免 C# 中的异常,继续执行代码吗?

c# - 在 .Net 中打印

visual-studio - 自定义项目模板组

.net - Sqlite 删除速度非常慢 - 如何加快速度?

c# - 动态创建类到cs文件?

.net - 参数未声明。由于其保护级别,它可能无法访问

java - JAXB 更新 XML 元素

c# - 在 C# 中使用 XSLT 转换 XML

java - 从两个不同的类登录 xml 的正确方法是什么?现在我在生成的 xml 中遇到错误