Read environment variables in ASP.NET Core

Your problem is spaces around =.

This will work (attention to space before closing quote):

Console.WriteLine(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT "));

The space after ASPNETCORE_ENVIRONMENT in this code is not a typo! The problem in the question was having extra space (in SET…), so you must use the same space in GetEnvironmentVariable().

As noted by Isantipov in a comment, an even better solution is to remove the spaces entirely from the SET command:

set ASPNETCORE_ENVIRONMENT=Production

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)