5

I have web.config with these two env variables that i need to remove see below 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" />

I am trying to remove those variables using

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>

Could not transform the file 'D:\Octopus\Applications\Widgets\XW QA\WidgetsAPI\2019.9.5_2\web.config' using the pattern 'web.Release.config'.

  • **Tip:** In this day and age of CI+CD, its arguably better to not use config transforms at all and place static config files into separate SCM repos and deploy them to the appropriate environment. A config file shouldn't be at the mercy of being "built" –  Sep 05 '19 at 21:46
  • Possible duplicate of [How to remove a ConnectionString using Config Transformations](https://stackoverflow.com/questions/8920451/how-to-remove-a-connectionstring-using-config-transformations) – gpro Sep 06 '19 at 08:14

1 Answers1

5

Using below i was able to resolve the issue.

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

  • This works great although I get the following warning for some reason: warning : No element in the source document matches '/configuration/system.webServer/aspNetCore/environmentVariables/environmentVariable[@name='COMPLUS_ForceENC']' – Gary Brunton Oct 15 '19 at 18:34