Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run ASP.NET Core application in "Development" environment

I am using ASP.NET Core RC2 and when I run dotnet run my application always runs in "Production". I am not able to change it to "Development".

I have the following launchSettings.json file:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:26088/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MVCCoreRc2App": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

I am not sure why dotnet is running the application in "Production" when I am setting "ASPNETCORE_ENVIRONMENT": "Development".

This was working in ASP.NET Core RC1. What am I missing?

like image 842
Miguel Moura Avatar asked May 24 '16 12:05

Miguel Moura


People also ask

Can we develop web application using .NET Core?

NET Framework allows developers to create Windows desktop and server-based apps, including ASP.NET Web applications. On the other hand, . NET Core is used to develop server applications that run on different OS – Windows, Mac, and Linux. However, it doesn't support creating desktop applications with a user interface.

How do I run a .NET Core app in VS code?

You can run an ASP.NET Core application from Visual Studio Code directly. To accomplish this, open the Command Palette, type dnx and press Enter. Next, select dnx: Run Command and press Enter. Then click dnx web.


3 Answers

launchsettings.json is used when launching from Visual Studio, but not from the command line dotnet.exe.

On the console set the environment variable before calling dotnet run.

set ASPNETCORE_ENVIRONMENT=Development

like image 109
Tratcher Avatar answered Oct 23 '22 09:10

Tratcher


If you're using Bash, the appropriate line is:

export ASPNETCORE_ENVIRONMENT=Development

You can set this in your ~/.bashrc file to make it apply whenever you log in.

like image 21
Drew Noakes Avatar answered Oct 23 '22 11:10

Drew Noakes


You can even change the environment at the command line when you run your application as in:

dotnet run environment=development
like image 25
Mally Nag Avatar answered Oct 23 '22 11:10

Mally Nag