title: Preprocessor directives across different projects
body: <p>Now before this is marked as duplicate I saw <a href="https://stackoverflow.com/questions/13836501/preprocessor-directives-across-different-files-in-c-sharp">other</a>, <a href="https://stackoverflow.com/questions/38771195/is-it-possible-to-keep-precompiled-symbols-in-c-sharp-assemblies-for-use-in-a-re?noredirect=1&amp;lq=1">similar</a>, <a href="https://stackoverflow.com/questions/5149351/solution-wide-define">related</a> questions, but I don't really think they are a good fit to my scenario.</p>
  
  <p>I'm dealing with <strong>badly written</strong>, <strong>evil</strong> code that I have no choice but to use in unit tests. It is essentially a library to read and merge some special formatted config files. Now in the code assumption is made that it will be used from executable applications, so it tries to load <code>.exe</code> config files. Obviously this is not the case if used from unit tests, so it fails by throwing an exception.</p>
  
  <p>To somehow overcome this limitation, I want to use preprcessor directives to change some parts of the code when used from unit test project.</p>
  
  <p>Let's say I have 3 projects.</p>
  
  <ol>
  <li>Class library project -> <strong>Evil</strong></li>
  <li>Console application project -> <strong>Proj1</strong> (references <strong>Evil</strong>)</li>
  <li>Unit test project     -> <strong>Test1</strong> (references <strong>Proj1</strong> and <strong>Evil</strong>)</li>
  </ol>
  
  <p><strong>Test1</strong> &amp; <strong>Evil</strong> have additional <code>UNITTEST</code> symbol defined (Build tab -> Conditional compilation symbols), and <strong>Evil</strong> has some code like this</p>
  
  <pre><code>#if !UNITTEST
  // do evil stuff
  #else
  // do stuff for unit test
  #endif
  </code></pre>
  
  <p>Now what I want is to define <code>#UNITTEST</code> in <strong>Test1</strong> project's test class and have it reflected in <strong>Evil</strong> project. </p>
  
  <p>From what I've seen in other answers - the only suggested way is to build with proper symbols for each case (when running unit tests, when debugging locally, when preparing a package for release), which looks cumbersome to me. </p>
  
  <p>What I'm looking for is a way to do less manual intervention and be able to easily have the version I need. As an example, when I build and <strong>Test1</strong> has <code>UNITTEST</code> symbol defined then <strong>Evil</strong> is built with <code>UNITTEST</code> symbol as well (and copied to <strong>Test1's</strong> output) and the <strong>Proj1</strong> will always reference version of <strong>Evil</strong> built with <code>DEBUG</code> or <code>RELEASE</code> based on <strong>Proj1's</strong> setup.</p>
  
  <p>Is there any way to achieve this ? </p>
  
  <p>I'm open to other suggestions to solve the problem. 
  Unfortunately refactoring/replacing <strong>Evil</strong> with something else is not an option (too much effort which can't be done now).</p>