使用ASP.NET Core在Angular项目模板中将开发环境设置为本地生产

问题描述 投票:0回答:1

使用带有ASP.NET Core的Angular项目模板,角度版本为5,Dotnet Core 2.1

在这里,我尝试将本地环境设置为“生产”作为此命令

$env:ASPNETCORE_ENVIRONMENT = "Production"

然后启动DOTNET WATCH RUN

在此之后,我仍然在“开发模式”中拥有自己的环境

那有什么问题吗?我认为我做对了enter image description here

angular asp.net-core development-environment
1个回答
4
投票

./Properties/launchSettings.json里面,你会看到这样的东西:

{
    ...
    "profiles": {
        ...
        "DatingAppDemo": {
            ...
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        }
    }    
}

请注意,ASPNETCORE_ENVIRONMENT的值设置为Development,它会覆盖您使用$env命令设置的值。

要解决此问题,您有三种选择:

  1. 只需将ASPNETCORE_ENVIRONMENTDevelopment更改为Production中的launchSettings.json
  2. 使用dotnet watch run --no-launch-profile,它指示dotnet进程不从launchSettings.json加载设置。
  3. launchSettings.json添加其他个人资料。例如。: "DatingAppDemoProduction": { ... "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" } } 您可以将此新配置文件与dotnet watch run --launch-profile DatingAppDemoProduction一起使用。

除非您决定使用选项2,否则您将不再需要设置$env:ASPNETCORE_ENVIRONMENT,因为这将按照描述从launchSettings.json获取。

© www.soinside.com 2019 - 2024. All rights reserved.