Skip to content

Not getting environment from DOTNET_ENVIRONMENT variable #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
charring opened this issue May 6, 2023 · 1 comment
Closed

Not getting environment from DOTNET_ENVIRONMENT variable #718

charring opened this issue May 6, 2023 · 1 comment

Comments

@charring
Copy link

charring commented May 6, 2023

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");
@charring
Copy link
Author

Nevermind. You have to open a new cmd window for env var edits to be applied in Configuration. But I guess that's not the case for GetEnvironmentVariable()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant