使用ASP.NET Core在Angular项目模板中将开发环境设置为本地生产 [英] Setting Development Environment to Production locally in Angular project template with ASP.NET Core
问题描述
在ASP.NET Core中使用Angular项目模板,其中 有角度的版本是5 Dotnet Core 2.1
Using Angular project template with ASP.NET Core where An angular version is 5, Dotnet Core 2.1
在这里,我尝试将本地环境设置为生产" 以此命令
here I tried to set my local Environment to "Production" as this command
$env:ASPNETCORE_ENVIRONMENT = "Production"
然后启动DOTNET WATCH RUN
此后,我的环境仍处于开发模式"
after this, I am still having my environment in "Development Mode"
那么有什么问题吗? 我想我做对了
So is there is any problem? I think I am doing right
推荐答案
在./Properties/launchSettings.json
内,您将看到类似以下的内容:
Inside of ./Properties/launchSettings.json
, you'll have something that looks like this:
{
...
"profiles": {
...
"DatingAppDemo": {
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
请注意,此处ASPNETCORE_ENVIRONMENT
的值设置为Development
,它会覆盖您使用$env
命令设置的值.
Notice here that the value for ASPNETCORE_ENVIRONMENT
is set to Development
, which overrides the value you've set using the $env
command.
要解决此问题,您有三个选择:
To resolve this, you have three options:
- 只需将
ASPNETCORE_ENVIRONMENT
从Development
更改为launchSettings.json
中的Production
. - 使用
dotnet watch run --no-launch-profile
,它指示dotnet
进程不从launchSettings.json
加载设置. -
向
launchSettings.json
添加其他配置文件.例如:
- Simply change
ASPNETCORE_ENVIRONMENT
fromDevelopment
toProduction
inlaunchSettings.json
. - Use
dotnet watch run --no-launch-profile
, which instructs thedotnet
process to not load settings fromlaunchSettings.json
. Add an additional profile to
launchSettings.json
. e.g.:
"DatingAppDemoProduction": {
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
您可以将此新配置文件与dotnet watch run --launch-profile DatingAppDemoProduction
一起使用.
You can use this new profile with dotnet watch run --launch-profile DatingAppDemoProduction
.
除非您决定使用选项2,否则您将不再需要设置$env:ASPNETCORE_ENVIRONMENT
,因为这将如所述从launchSettings.json
中获取.
Unless you decide to use option 2, you'll no longer need to set $env:ASPNETCORE_ENVIRONMENT
as this will be taken from launchSettings.json
as described.
这篇关于使用ASP.NET Core在Angular项目模板中将开发环境设置为本地生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!