title: Conditional compilation constant not working in a .net core multitargeted sdk-style project
body: <p>Here is how the conditional compilation constants were initially defined (notice multitargeting):</p>
  
  <pre><code>&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFrameworks&gt;netstandard2.0;netcoreapp2.0;net461&lt;/TargetFrameworks&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netstandard2.0'"&gt;
      &lt;DefineConstants&gt;NETCORE;&lt;/DefineConstants&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;PropertyGroup Condition=" '$(TargetFramework)' == 'net461'"&gt;
      &lt;DefineConstants&gt;NETFULL;&lt;/DefineConstants&gt;
    &lt;/PropertyGroup&gt;
    ...
  
  &lt;/Project&gt;
  </code></pre>
  
  <p><strong>At that time <code>NETCORE</code> constant was working fine.</strong></p>
  
  <pre><code>#if NETCORE
      // Works Fine! Not gray in VS; Compiler recognizes code!
      public string Abc { get; set; }   
  #endif
  </code></pre>
  
  <p>I was working with my code and my assembly didn't compile at that time.</p>
  
  <hr>
  
  <p>After that I added additional conditional compilation constant (not editing the previous ones - <code>NETFULL</code> and <code>NETCORE</code>):</p>
  
  <pre><code>&lt;PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0'"&gt;
      &lt;DefineConstants&gt;NETCOREONLY;&lt;/DefineConstants&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p><em>Overall code (assembly) still not compiling.</em></p>
  
  <p>And deleted this additional <code>NETCOREONLY</code> as not needed, leaving only the previous ones (<code>NETCORE</code> and <code>NETFULL</code>).</p>
  
  <p><em>Overall code (assembly) still not compiling.</em></p>
  
  <p><strong>The problem is that <code>NETCORE</code> stopped working like it had been before.</strong></p>
  
  <p>I'm switching to <code>netcoreapp2.0</code> platform, but the code in</p>
  
  <pre><code>#if NETCORE
      // Problem; Stays gray in VS; 
      // Compiler does not understand that it shoud consume this code
      public string Abc { get; set; }   
  #endif
  </code></pre>
  
  <p>is not visible to compiler. It stays gray in VS. As if it is not <code>netcoreapp2.0</code>.</p>
  
  <p>The following declaration</p>
  
  <pre><code>  &lt;PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' OR '$(TargetFramework)' == 'netstandard2.0'"&gt;
      &lt;DefineConstants&gt;NETCORE;&lt;/DefineConstants&gt;
    &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>should make <code>NETCORE</code> constant work for <code>netcoreapp2.0</code>, but it doesn't.</p>