7

I have updated my ASP.NET 5 project to beta 8, and we are now supposed to the following web command

"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
},

Now i have updated my project with the environment variables.

enter image description here

This has also updated my launchSettings.json file, as so

{
  "profiles": {
    "web": {
      "commandName": "web",
      "environmentVariables": {
        "ASPNET_ENV": "Development"
      }
    }
  }
}

But for some reason, every time I run the command dnx web it says that the hosting environment is Production. Why is it not starting in development mode?

enter image description here

3 Answers 3

13

The settings in launchSettings.json are only used by VS. If you run from a console, you have to set that environment variable manually.

CMD:

set ASPNET_ENV=Development
dnx web

PS:

$env:ASPNET_ENV=Development
dnx web
Sign up to request clarification or add additional context in comments.

3 Comments

this is also working: dnx web ASPNET_ENV=Development
set ASPNET_ENV=Development does not work. dnx web ASPNET_DEV=Development does work though.
How to set this environment variable during the build process? I am guessing it will need to be updated to "staging" and "production" as and when it is deployed to these environments
1

Adding to @Victor Hurdugaci answer, you could also avoid "messing" with current environment by passing needed variables on command line.

Inside project.json file, say that you have a web-dev command specific for development environment:

"commands": {
  "web-dev": "Microsoft.AspNet.Server.Kestrel 
    --ASPNET_ENV Development --Hosting:Environment Development 
    --config hosting.Development.json",
},

where you can see how both ASPNET_ENV, Hosting:Environment are set, as well as invoking a specific hosting.json configuration.
NOTE: command is split on several lines just for readability, join again before actually pasting in JSON file.

Comments

0

The command: set ASPNET_ENV=Development is now obsolete instead you can use CMD:

set ASPNETCORE_ENVIRONMENT=Development

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.