ASP.NET Core Isdevelopment

Asked

Viewed 489 times

4

When creating a project with the dotnet cli

dotnet new Razor -o Razorpagescontacts

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

Since in the Startup.cs I have

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

And never gets into the app.UseDeveloperExceptionPage() using the dotnet run

2 answers

5


To work with different environments in . NET Core you need to name the environment in the variable ASPNETCORE_ENVIRONMENT

Command Prompt

set ASPNETCORE_ENVIRONMENT=Development

Powershell

$Env:ASPNETCORE_ENVIRONMENT = "Development"

It is worth mentioning that the changes of 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 in the Windows Environment Variables.

  1. Go to Control Panel > System > Advanced System Settings

  2. Click on Environment variables

inserir a descrição da imagem aqui

  1. Click on New and attribute the Name and Valor of the Environment Variable.

inserir a descrição da imagem aqui

For more information, visit Working with Multiple Environments

3

  • Using setx did not work using the vscode console. No vscode worked with $Env:ASPNETCORE_ENVIRONMENT = "Development"

  • 'Cause then it’s powershell

  • Yes, you could put in your answer the two options, both for CMD and powershell

Browser other questions tagged

You are not signed in. Login or sign up in order to post.