33

I want to get the environment variable in csproj, because there I have a condition which exclude appsettings from publish.

enter image description here enter image description here
I want this because, my appsettings didn't depends to Solution Configuration, them depends only from environment variables.

Instead of '$(Configuration)' != Debug' I want something like 'envVariable != Development' etc.

Or is it another method to exclude those files regarding to env variables?

in C# is this method: Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT ").

Alex
  • 1,013
  • 1
  • 13
  • 27

1 Answers1

46

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.

Barak Gall
  • 1,422
  • 12
  • 24