'Asp.net core 6 app on Azure uses Development environment by default?

I'm using ASP.NET Core 6. On my local machine, it correctly uses my development app settings (the ones from appsettings.Development.json) thanks to launchSettings.json.

When I publish it on a linux server, it correctly uses my production app settings (the ones from appsettings.json).

But when I upload it to Azure, it uses by default the development environment and I am clueless why. I even added ASPNETCORE_ENVIRONMENT set to Production in Azure, but it is ignored. My only workaround is to remove the appsettings.Development.json file from the server...

Any idea what could be causing that?



Solution 1:[1]

By searching ASPNETCORE_ENVIRONMENT in the solution, I found it to be set to Development in a web.config file. I remember that I tried to run the app locally under IIS but can't remember that I set the variable. I guess it created the file at that time.

So if you are in the same situation, think about the web.config file which could affect the publication to Azure.

Update: I made the test. I created an IIS launch config. VS created the web.config file. Then I manually added ASPNETCORE_ENVIRONMENT in the UI. It added it to the web.config file. In the UI, I then removed the env var. Guess what? It didn't remove it from the file...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1