Dotnet core ignores ASPNETCORE_ENVIRONMENT variable
I suspect that the issue you're encountering is that the ASPNETCORE_ENVIRONMENT
variable is defined in the C:\devel\apps\webapi\Properties\launchSettings.json
file.
The way dotnet run
works is it loads this file and finds the first profile which commandName
is project
, and uses it to run the application. There's a high chance, if you haven't made any changes to that file, that the environmentVariables
section of that profile contains the ASPNETCORE_ENVIRONMENT
variable set to Development
.
You have 2 options if you want to run the app in Production
mode:
- change the existing profile and set the variable to
Production
, meaning every time you executedotnet run
, it's going to run the app in production mode; or - add a new profile where the
ASPNETCORE_ENVIRONMENT
variable is set toProduction
. You can then use it if you executedotnet run --launch-profile <name-of-your-new-profile>
The problem is how you have set the environment variable. On the command line you don't need the quotes, so you should instead have this:
C:\> set ASPNETCORE_ENVIRONMENT=Production
C:\> echo %ASPNETCORE_ENVIRONMENT%
Production