title: How do you pass conditional compilation symbols (DefineConstants) to msbuild
body: <p>So, both <a href="https://stackoverflow.com/questions/479979/msbuild-defining-conditional-compilation-symbols">this</a> and <a href="http://msdn.microsoft.com/en-us/library/bb629394.aspx" rel="noreferrer">this</a> are pretty clear. Simply pass <code>/p:DefineConstants="SYMBOL"</code></p>
  
  <p>It doesn't work at all for me, even in a test project. I'm expecting that passing /p:DefineConstants="SYMBOL" will override any conditional compilation constants defined in the csproj. Not the case however...</p>
  
  <p>Full code listing below:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace DefineConstants
  {
      class Program
      {
          static void Main(string[] args)
          {
  #if DEV
              Console.WriteLine("DEV");
  #elif UAT 
              Console.WriteLine("UAT");
  #else
              Console.WriteLine("No environment provided");
  #endif
          }
      }
  }
  </code></pre>
  
  <p>.csproj file is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup&gt;
      &lt;Configuration Condition=" '$(Configuration)' == '' "&gt;Debug&lt;/Configuration&gt;
      &lt;Platform Condition=" '$(Platform)' == '' "&gt;x86&lt;/Platform&gt;
      &lt;ProductVersion&gt;8.0.30703&lt;/ProductVersion&gt;
      &lt;SchemaVersion&gt;2.0&lt;/SchemaVersion&gt;
      &lt;ProjectGuid&gt;{57A2E870-0547-475C-B0EB-66CF9A2FE417}&lt;/ProjectGuid&gt;
      &lt;OutputType&gt;Exe&lt;/OutputType&gt;
      &lt;AppDesignerFolder&gt;Properties&lt;/AppDesignerFolder&gt;
      &lt;RootNamespace&gt;DefineConstants&lt;/RootNamespace&gt;
      &lt;AssemblyName&gt;DefineConstants&lt;/AssemblyName&gt;
      &lt;TargetFrameworkVersion&gt;v3.5&lt;/TargetFrameworkVersion&gt;
      &lt;FileAlignment&gt;512&lt;/FileAlignment&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "&gt;
      &lt;PlatformTarget&gt;x86&lt;/PlatformTarget&gt;
      &lt;DebugSymbols&gt;true&lt;/DebugSymbols&gt;
      &lt;DebugType&gt;full&lt;/DebugType&gt;
      &lt;Optimize&gt;false&lt;/Optimize&gt;
      &lt;OutputPath&gt;bin\Debug\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;TRACE;DEBUG&lt;/DefineConstants&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "&gt;
      &lt;PlatformTarget&gt;x86&lt;/PlatformTarget&gt;
      &lt;DebugType&gt;pdbonly&lt;/DebugType&gt;
      &lt;Optimize&gt;true&lt;/Optimize&gt;
      &lt;OutputPath&gt;bin\Release\&lt;/OutputPath&gt;
      &lt;DefineConstants&gt;TRACE&lt;/DefineConstants&gt;
      &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
      &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;Reference Include="System" /&gt;
      &lt;Reference Include="System.Core" /&gt;
      &lt;Reference Include="System.Xml.Linq" /&gt;
      &lt;Reference Include="System.Data.DataSetExtensions" /&gt;
      &lt;Reference Include="System.Data" /&gt;
      &lt;Reference Include="System.Xml" /&gt;
    &lt;/ItemGroup&gt;
    &lt;ItemGroup&gt;
      &lt;Compile Include="Program.cs" /&gt;
      &lt;Compile Include="Properties\AssemblyInfo.cs" /&gt;
    &lt;/ItemGroup&gt;
    &lt;Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /&gt;
    &lt;!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
         Other similar extension points exist, see Microsoft.Common.targets.
    &lt;Target Name="BeforeBuild"&gt;
    &lt;/Target&gt;
    &lt;Target Name="AfterBuild"&gt;
    &lt;/Target&gt;
    --&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>built using:</p>
  
  <pre><code>C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild DefineConstants.sln /p:DefineConstants="DEV;DEBUG" /p:Configuration="Debug" /p:Platform="x86"
  </code></pre>
  
  <p>Running the program shows:</p>
  
  <pre><code>No environment provided
  </code></pre>
  
  <p><strong>Help!</strong></p>