Home > Software design >  ASPNETCORE_ENVIRONMENT no longer overrides DOTNET_ENVIRONMENT?
ASPNETCORE_ENVIRONMENT no longer overrides DOTNET_ENVIRONMENT?

Time:01-31

According to the docs, ASPNETCORE_ENVIRONMENT is suppose to override the DOTNET_ENVIRONMENT environment variable. So, I've went ahead and added a DOTNET_ENVIRONMENT entry set to Development on my machine's system environment variables.

On one of my projects, I had to create a new custom profile which should only be used when my app uses Kestrel (ex.: run from within VS). In order for my custom profile to be picked up, I've added the following section to one of the profiles:

"profiles": {
      "Grm.ClientManagementSite.Wasm.Server": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "applicationUrl": "https://localhost:7126;http://localhost:5126",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Local"
        }
      },
...
}

I've noticed that whenever I run this profile, the environment is always set up as Development (which is defined by the global system entry I've added to the machine's system environment variables).

I've also noticed that if I use the DOTNET_ENVIRONMENT variable, then my custom profile will get picked up. I'm almost positive that my previous setting (using ASPNETCORE_ENVIRONMENT for overriding the profile on the lauchSettings.json) was working when I've created this project. Does anyone know it this is known issue with .NET 7.0?

Thanks.

CodePudding user response:

Yes, starting .NET 7 Preview 3 when using WebApplicationBuilder DOTNET_ varaibles have higher priority then ASPNETCORE_ ones. See this github issue or this breaking change article.

UPD JIC:

  • Created an issue in ASP.NET Core repo
  • Created PR to docs.
  • Related