ASP.NET Core IsDevelopment

4

When creating a project with dotnet cli

/ em>

  

dotnet new razor -o RazorPagesContacts

How do I change the environment variable to developer mode when running the application using dotnet run .

Since no Startup.cs I have

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else
{
    app.UseExceptionHandler("/Error");
}

And never enter app.UseDeveloperExceptionPage() using dotnet run

    
asked by anonymous 20.12.2017 / 16:15

2 answers

5

To work with different .NET Core environments, you must assign the environment name to the variable ASPNETCORE_ENVIRONMENT

Command Prompt

set ASPNETCORE_ENVIRONMENT=Development

Powershell

$Env:ASPNETCORE_ENVIRONMENT = "Development"

Note that changes to the environment variable through the Command Line or PowerShell will only be available until the window is closed.

To assign the value of this environment variable globally, you must assign the value to the Windows Environment Variables.

  • Access Control Panel > System > Advanced System Settings

  • Click Environment Variables

  • Click New and assign of the Environment Variable.
  • Formoreinformation,visit Working with Multiple Environments

        
    20.12.2017 / 16:31
    3

    You need to assign the "Development" value to the ASPNETCORE_ENVIROMENT environment variable. Before running "dotnet run" run the command below:

    CMD Console

    setx ASPNETCORE_ENVIRONMENT "Development"
    

    PowerShell

    $Env:ASPNETCORE_ENVIRONMENT = "Development"
    
      

    Source: link

        
    20.12.2017 / 16:21