【问题标题】:Setting Development Environment to Production locally in Angular project template with ASP.NET Core使用 ASP.NET Core 在 Angular 项目模板中将开发环境设置为本地生产
【发布时间】:2018-09-16 16:10:24
【问题描述】:
在 ASP.NET Core 中使用 Angular 项目模板
角度版本是 5,
点网核心 2.1
在这里我尝试将本地环境设置为“生产”
作为这个命令
$env:ASPNETCORE_ENVIRONMENT = "Production"
然后启动DOTNET WATCH RUN
在此之后,我的环境仍然处于“开发模式”
那么有什么问题吗?
我认为我做得对
【问题讨论】:
标签:
angular
asp.net-core
development-environment
【解决方案1】:
在./Properties/launchSettings.json 内部,您将拥有如下所示的内容:
{
...
"profiles": {
...
"DatingAppDemo": {
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
注意这里ASPNETCORE_ENVIRONMENT 的值设置为Development,它覆盖您使用$env 命令设置的值。
要解决此问题,您有三个选择:
- 只需在
launchSettings.json 中将ASPNETCORE_ENVIRONMENT 从Development 更改为Production。
- 使用
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 获取。