How To: Conditionally Apply Metadata to Items

Last week we got a great question over on our forum about applying metadata to items depending on a condition. What the author wanted to was something like this:

 <ItemGroup>
  <Compile Include="MyClass.boo">
   <DefineConstants Condition=" '$(Configuration)' == 'Debug'>OnForThisFile</DefineConstants>
  </Compile>
 </ItemGroup>

It isn't documented in our MSDN reference (which we'll get fixed), but as the original author discovered this works exactly as you'd hope. Pretty nifty!

[ Author: Neil Enns ]