title: Compiler Additional Options computed in a custom Target
body: <p>I have a msbuild custom Target and a Task computing a Value. 
  The Task will output the Value as Property.
  This Property I would like to uses as Additional Option to the Compiler call.</p>
  
  <p>But the Property is empty when used as Additional Option.</p>
  
  <p>My <strong>*.targets</strong> File looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;UsingTask TaskName="GetBranchName_TASK" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" &gt;
      &lt;ParameterGroup&gt;
          &lt;sPath ParameterType="System.String" Required="true" /&gt;
          &lt;sBranchName ParameterType="System.String" Output="true" /&gt;
      &lt;/ParameterGroup&gt;
      &lt;Task&gt;
        &lt;Code Type="Fragment" Language="cs"&gt;
          &lt;![CDATA[
              ... some Code ...
          ]]&gt;
        &lt;/Code&gt;
      &lt;/Task&gt;
    &lt;/UsingTask&gt;
  
    &lt;Target Name="GetBranchName_TARGET"&gt;
      &lt;GetBranchName_TASK sPath="$(MSBuildThisFileDirectory)"&gt;
        &lt;Output PropertyName="BranchName" TaskParameter="sBranchName" /&gt;
      &lt;/GetBranchName_TASK&gt;
      &lt;Message Importance="High" Text="BranchName = $(BranchName)" /&gt;
    &lt;/Target&gt;
  
    &lt;PropertyGroup&gt;
      &lt;BuildDependsOn&gt;
          GetBranchName_TARGET;
          $(BuildDependsOn);
      &lt;/BuildDependsOn&gt;
    &lt;/PropertyGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>My <strong>*.props</strong> File is like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup Label="Configuration"&gt;
      ... some Properties here ...
    &lt;/PropertyGroup&gt;
    &lt;Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /&gt;
    &lt;Import Project="IRSGetBranchName.targets" /&gt; 
    &lt;ItemDefinitionGroup&gt;
      &lt;ClCompile&gt;
        &lt;AdditionalOptions&gt;/DBRANCHNAME=$(BranchName) /DMORE=BAR&lt;/AdditionalOptions&gt;
      &lt;ClCompile&gt;
    &lt;ItemDefinitionGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>This <strong><em>.props</strong> File then is imported into several <strong></em>.vcxproj</strong></p>
  
  <p>The Value printed as Message in my <em>GetBranchName_TARGET</em> is correct as expected (showing the correct TFS-Branch Name). 
  But when looking at <em>Detailed Build Output</em>, the Value seems empty:</p>
  
  <pre><code>1&gt;ClCompile
  1&gt;    ..\FOO.cpp
  1&gt;        AdditionalOptions = /DBRANCHNAME= /DMORE=BAR
  </code></pre>
  
  <p>I tried for hours but found no solution and I really hope someone help whats wrong here ...</p>
  
  <p>a) Is the Property <strong>BranchName</strong> not available globally? I tried to print the Property from other custom Targets and it worked well!</p>
  
  <p>b) Or is the <em>ClCompile.AdditionalOptions</em> evaluated/build before my Target is excuted? In this case how can I re-evaluate?</p>
  
  <p>c) ...</p>
  
  <p>I'am very thankful for any Input.</p>