使用带有ASP.NET Core的Angular项目模板,角度版本为5,Dotnet Core 2.1
在这里,我尝试将本地环境设置为“生产”作为此命令
$env:ASPNETCORE_ENVIRONMENT = "Production"
然后启动DOTNET WATCH RUN
在此之后,我仍然在“开发模式”中拥有自己的环境
在./Properties/launchSettings.json
里面,你会看到这样的东西:
{
...
"profiles": {
...
"DatingAppDemo": {
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
请注意,ASPNETCORE_ENVIRONMENT
的值设置为Development
,它会覆盖您使用$env
命令设置的值。
要解决此问题,您有三种选择:
ASPNETCORE_ENVIRONMENT
从Development
更改为Production
中的launchSettings.json
。dotnet watch run --no-launch-profile
,它指示dotnet
进程不从launchSettings.json
加载设置。launchSettings.json
添加其他个人资料。例如。:
"DatingAppDemoProduction": {
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
您可以将此新配置文件与dotnet watch run --launch-profile DatingAppDemoProduction
一起使用。除非您决定使用选项2,否则您将不再需要设置$env:ASPNETCORE_ENVIRONMENT
,因为这将按照描述从launchSettings.json
获取。