使用ASP.NET Core在Angular项目模板中将开发环境设置为本地生产 [英] Setting Development Environment to Production locally in Angular project template with ASP.NET Core

查看:126
本文介绍了使用ASP.NET Core在Angular项目模板中将开发环境设置为本地生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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:

  1. 只需将ASPNETCORE_ENVIRONMENTDevelopment更改为launchSettings.json中的Production.
  2. 使用dotnet watch run --no-launch-profile,它指示dotnet进程launchSettings.json加载设置.
  3. launchSettings.json添加其他配置文件.例如:

  1. Simply change ASPNETCORE_ENVIRONMENT from Development to Production in launchSettings.json.
  2. Use dotnet watch run --no-launch-profile, which instructs the dotnet process to not load settings from launchSettings.json.
  3. 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屋!

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