简体   繁体   中英

How to determine which environment asp.net core app will run in?

The documentation states that If ASPNETCORE_ENVIRONMENT isn't set, it defaults to Production .

My machine doesn't seem to have ASPNETCORE_ENVIRONMENT environment variable set at all, as evidenced by running:

c:\>set ASPNETCORE_ENVIRONMENT    
Environment variable ASPNETCORE_ENVIRONMENT not defined

So theoretically, my project (brand new from Visual Studio template), should run in Production, but...

c:\dotnet run
Hosting environment: Development

What am I missing?

This is because the dotnet run command uses the the launchsetting.json file.

You can execute the command with --no-launch-profile option so that run command does not load the launch settings file and thereby the environment variables.

If you want to use launchsetting file and sepcific profile setting from that file, then create one and use switch --launch-profile <NAME>

Hope this helps. Refer documentation for command line switches usage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM