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.
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?
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With