I created a simple webapi project with dotnet core.
I'm trying to set the running environment using the ASPNETCORE_ENVIRONMENT system variable.
C:\devel\apps\webapi>set ASPNETCORE_ENVIRONMENT=Production
C:\devel\apps\webapi>echo %ASPNETCORE_ENVIRONMENT%
Production
C:\devel\apps\webapi>dotnet run
Using launch settings from C:\devel\apps\webapi\Properties\launchSettings.json...
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using 'C:\Users\SSCARANO\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Hosting environment: Development
Content root path: C:\devel\apps\webapi
Now listening on: https://localhost:5001
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
I tried opening a different console, and also setting it logged in as administrator, but the app is always running on Development mode.
I saw this (https://stackoverflow.com/a/40102470/47633) related question, but I'm not using IIS
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:
Production
, meaning every time you execute dotnet run
, it's going to run the app in production mode; orASPNETCORE_ENVIRONMENT
variable is set to Production
. You can then use it if you execute dotnet 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With