如何确定asp.net core app将在哪个环境中运行? [英] How to determine which environment asp.net core app will run in?

查看:21
本文介绍了如何确定asp.net core app将在哪个环境中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档 指出如果未设置 ASPNETCORE_ENVIRONMENT,则默认为 Production.

我的机器似乎根本没有设置 ASPNETCORE_ENVIRONMENT 环境变量,运行如下:

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

所以理论上,我的项目(来自 Visual Studio 模板的全新项目)应该在生产环境中运行,但是...

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

c:\dotnet run
Hosting environment: Development

我错过了什么?

推荐答案

这是因为 dotnet run 命令使用了 launchsetting.json 文件.

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

您可以使用 --no-launch-profile 选项执行命令,这样运行命令就不会加载启动设置文件,从而不会加载环境变量.

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.

如果您想使用该文件中的启动设置文件和特定的配置文件设置,请创建一个并使用开关 --launch-profile <NAME>

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.

这篇关于如何确定asp.net core app将在哪个环境中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆