Search code examples
asp.net.netwindowsvisual-studioasp-net-config-builders

Config Builder Not Finding Environment Variable


When I view the connection string while debugging, the value is "abc"; not what I've set the Windows environment variable to.

web.config

<configSections>
  <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>

<configBuilders>
   <builders>
      <add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   </builders>
</configBuilders>

<connectionStrings configBuilders="Environment">
   <add name="myConnection" connectionString="abc" providerName="System.Data.SqlClient"/
</connectionStrings>

I've double checked that the correct Nuget packages are installed, that the framework is correctly on 4.7.2, that my spelling is correct, and I've read the Microsoft docs on Configuration Builders several times.


Solution

  • In the Microsoft document linked above, Configuration builders for ASP.NET, there exists the following footnote:

    Note: You might need to exit and restart Visual Studio to see changes in environment variables.

    That fixed it.