Skip to content

Not getting environment from DOTNET_ENVIRONMENT variable #718

@charring

Description

@charring

I set DOTNET_ENVIRONMENT to "Development" but app still thinks is "Production"

#r "sdk:Microsoft.NET.Sdk.Web"

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;

var builder = WebApplication.CreateBuilder();
var app = builder.Build();

app.Logger.LogInformation($"EnvironmentName: {app.Environment.EnvironmentName}"); // EnvironmentName: Production
// above should be Development

app.Logger.LogInformation($"IsDevelopment(): {app.Environment.IsDevelopment()}"); // IsDevelopment(): False
// above should be True

string env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT", EnvironmentVariableTarget.Machine);
app.Logger.LogInformation($"env: {env}"); // env: Development
// above shows that env var is set

app.MapGet("/", () => "Hello world");

app.Run("http://localhost:5178");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions