Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET 5 not running in development mode

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

like image 612
Gillardo Avatar asked Oct 27 '15 16:10

Gillardo


People also ask

How do you enable the Development environment?

The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.

What is development mode error?

Development Mode. Swapping to Development environment will display more detailed information about the error that occurred. Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users.

Where is ASPNETCORE_ENVIRONMENT?

In Visual Studio, we can set ASPNETCORE_ENVIRONMENT in the debug tab of project properties. Open project properties by right clicking on the project in the solution explorer and select Properties. This will open properties page. Click on Debug tab and you will see Environment Variables as shown below.


2 Answers

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
like image 92
Victor Hurdugaci Avatar answered Nov 15 '22 06:11

Victor Hurdugaci


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.

like image 35
superjos Avatar answered Nov 15 '22 07:11

superjos