I want to get the environment variable in csproj, because there I have a condition which exclude appsettings from publish.
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 ").
How to open a CSPROJ file. CSPROJ files are are meant to be opened and edited in Microsoft Visual Studio (Windows, Mac) as part of Visual Studio projects. However, because CSPROJ files are XML files, you can open and edit them in any text or source code editor.
In Visual Studio 2019 right-click your project, choose Properties . In the project properties window, select the Debug tab. Then, under Environment variables change the value of your environment from Development to Production or other environments.
In Visual Studio, we can set ASPNETCORE_ENVIRONMENT in the debug tab of project properties. Open project properties by right clicking on the project in the solution explorer and select Properties. This will open properties page. Click on Debug tab and you will see Environment Variables as shown below.
Click on System and Security and then on System. In the left pane, click on Advanced system settings. At the very bottom of the pop up, click on Environment Variables. Edit the Path variable and append the folder's path that contains the MSBuild.exe to it (e.g., ;C:\Windows\Microsoft.NET\Framework64\v4.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With