PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] How to get Environment Variable in csproj file?

 November 05, 2022     .net, appsettings, environment-variables     No comments   

Issue

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 ").


Solution

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.



Answered By - Barak Gall
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing