Monday, February 18, 2019

.NET Core 2.2 - web.config automatically adding in environmental variables section. How to prevent it?

I am working on a microservice in .NET Core 2.2 and encountered an issue another developer mentioned in a GitHub issue. When I run the project locally, the web.config file automatically adds in a section for environment variables:

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess"> <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="ENVIRONMENT_NAME_HERE" /> </environmentVariables> </aspNetCore> 

If I forget to undo/exclude the change when I check in my project to source control (Team Foundation Server), the project is built and published to three different hosts: Development, Sandbox, Production.

I am using IIS to host the service and the ASPNETCORE_ENVIRONMENT environment variable is set at the host system level. The modified web.config in the project alters the value of the variable by appending its value with the value the system variable holds. You then get values such as "Development;Development", "Sandbox;Development", "Production;Development".

I want to use the variable that is set on the host and not use the web.config. Is there a way to prevent the web.config of adding this extra section? I've worked with earlier versions of .NET Core and never encountered this issue before.

Please let me know if I need to clarify some things. Thanks!

.NET Core 2.2 - web.config automatically adding in environmental variables section. How to prevent it? Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team