So I ran into this same problem today and got it working rather easily. This was one of the first relevant results on google when I searched for this so thought I’d share.
Actually the $() operator is used to resolve any variable within the .csproj but it’s also seeded with environment variables already when MSBuild is triggered. So in your case you could do $(envVariable) or $(ASPNETCORE_ENVIRONMENT).
They’re brought in like any other .csproj variable.