title: Define a constant with an environment variable value that is expanded during COMPILE time
body: <p>In my csharp code I need to define a constant where its value is set from environment variable expansion during <strong>compile time</strong>.</p>
  
  <p>In this example let's talk about any arbitrary string, such as "Hello World".</p>
  
  <p>For c++ there seem to be various approaches. See the following answer, for example: <a href="https://stackoverflow.com/a/22828929">https://stackoverflow.com/a/22828929</a></p>
  
  <p>Surprisingly I wasn't able to find a similar solution for csharp.<br>
  In particular, there seems to be no way to tweak the "*.csproj" file accordingly?  </p>
  
  <p>PS:<br>
  As mentioned in the answer by Hans Passant below: there is some logic for "DefineConstants", but they only give you some kind of boolean flag, so you can use it for conditional statements such as "#if TESTFOO" in your source code. you will <em>not</em> be able to use the actual <em>value</em> of the environment variable.</p>
  
  <p>One possible "workaround" (to dynamically generate additional source files) is described in the following answer, for example: <a href="https://stackoverflow.com/a/4453285">https://stackoverflow.com/a/4453285</a></p>
  
  <p>But I'm still looking for an official solution that is more "straight".</p>