Amit Singh Rawat
Amit Singh Rawat

Reputation: 589

Setting Development Environment to Production locally in Angular project template with ASP.NET Core

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"

and then start 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 enter image description here

Upvotes: 1

Views: 1669

Answers (1)

Kirk Larkin
Kirk Larkin

Reputation: 93003

Inside of ./Properties/launchSettings.json, you'll have something that looks like this:

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

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. 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"
        }
    }
    

    You can use this new profile with dotnet watch run --launch-profile DatingAppDemoProduction.

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.

Upvotes: 6

Related Questions