Awesome Awesome - 1 month ago 23x
C# Question

Pass hosting environment for self-hosting

I'm trying to run ASP.NET Core (.NET 4.6.1) application as self hosting by means of weblistener

I've add a command:

"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"

and necessary dependencies in

When I start my application via Visual Studio it's works fine


ProjectName.exe starts as web server with
Hosting environment: Development

But when I run it by hand
runs with
Hosting environment: Production
and it's not working properly.
First of all I want find way to run application by hand with
Development environment

In VS I have this option:

enter image description here


When you start the application Visual Studio will automatically set the environment variables for you (based on settings from launchSettings.json in the properties folder).

When you run from commandline or double-click, you need to set the environment variable yourself using setx ASPNETCORE_ENVIRONMENT "Development" (Commandline) or $Env:ASPNETCORE_ENVIRONMENT = "Development" (Powershell).