Running my ASP.NET Core application using DNX, I was able to set environment variables from the command line and then run it like this:
set ASPNET_ENV = Prod
Your problem is spaces around =.
This will work (attention to space before closing quote):
Console.WriteLine(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT "));
Or remove spaces (better, see comment of @Isantipov below):
set ASPNETCORE_ENVIRONMENT=Production
P.S. Stop trying to "fix error with space" in this answer! It's not a typo! The real problem in question was with extra space (in SET...), so answer is either use same space in GetEnvironmentVariable() or remove it from SET... command!