3

I'm writing my own MS build scripts which I import in the project file (*.vcxproj)

I would like to execute a task conditionally depending on the C runtime being used dynamically. I tried the following:

Condition = " '$(RuntimeLibrary)' == 'MultiThreadedDLL' "

But $(RunitmeLibrary) is not a Property but an argument to ClCompile.

Is there any other way to write a condition that checks whether the runtime is liked dynamically or statically?

Regards

niks
  • 2,316
  • 1
  • 15
  • 15

1 Answers1

4

The value you are looking for is metadata of the ClCompile item group. Use this:

Condition=" '%(ClCompile.RuntimeLibrary)' == 'MultiThreadedDll' "

I added this to the bottom of a vcxproj to see what the current setting was:

 <Target Name="BeforeClCompile">
    <Message Text="BeforeCompile: RuntimeLibrary=[%(ClCompile.RuntimeLibrary)]" Importance="high" />
 </Target>
Brian Walker
  • 8,658
  • 2
  • 33
  • 35
  • 2
    Thank you, this is exactly what I was looking for. Except that it seems to be illegal to access %(ClCompile.RuntimeLibrary) within a Condition. (Error code MSB4191: The reference to custom metadata "RuntimeLibrary" at position 1 is not allowed in this condition '%(ClCompile.RuntimeLibrary)' == 'MultiThreadedDLL'. I've worked around this issue by creating a property that stores the value of this custom metadata and use the property in the condition. %(ClCompile.RuntimeLibrary) – niks Jan 19 '11 at 07:54
  • 2
    @niks Is there a way to define this property outside a target? When I'm doing this, `%(...)` is not evaluated, it remains the same string starting with percent sign. – Mikhail Dec 20 '14 at 20:40
  • To complete this answer, which leads in the right direction [here](https://social.msdn.microsoft.com/Forums/vstudio/en-US/109c2303-b4a5-4aa1-8f61-01663d358fa5/using-metadata-in-conditions?forum=msbuild) is an detailed answer how to get Parameter even in Post-Build events via $(RuntimeLibrary) as example. In VS 2015 I have to write @(ClCompile->'%(RuntimeLibrary)'->Distinct()) to get only one result of the ItemGroup – 42tg Feb 07 '17 at 14:35