Run ASP.NET Core application in "Development" environment
Asked Answered
W

3

9

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?

Whitfield answered 24/5, 2016 at 12:19 Comment(0)
A
12

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

Ats answered 24/5, 2016 at 14:21 Comment(2)
This not seems to be a permanent solution to me. Everytime I need to set this variable. What is I am hosting app with IIS?Display
@Vipul, set this variable on your PC rather than at the command line.Abstention
A
4

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.

Abstention answered 25/10, 2016 at 13:41 Comment(0)
R
2

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

dotnet run environment=development
Righteousness answered 7/12, 2016 at 13:41 Comment(1)
I like this solution the best, means I don't have to mess with the environment variables, just specify it in the command straight up.Subsistence

© 2022 - 2024 — McMap. All rights reserved.