1

Given a PreProcessor definition like the following:

<PreprocessorDefinitions>%(PreprocessorDefinitions);ENABLE_DEBUGGING=1;</PreProcessorDefinitions>

Is it possible to determine the value of ENABLE_DEBUGGING during an MSBuild post-build event?

user2506293
  • 805
  • 1
  • 7
  • 13

1 Answers1

0

Here's one of the probably multiple ways to do this; will only work if the ClCompile ItemGroup contains items, in other words when there are files to compile, and if they all have the same value for PreprocessorDefinitions; it stores the number found after the ENABLE_DEBUGGING= string in the DebugVal property.:

<Target Name="CheckValue" BeforeTargets="BuildGenerateSources">
  <PropertyGroup>
    <PreProc>%(ClCompile.PreprocessorDefinitions)</PreProc>
    <DebugVal>$([System.Text.RegularExpressions.Regex]::Match( $(PreProc), 'ENABLE_DEBUGGING=(\d)' ).Groups[ 1 ].Value )</DebugVal>
    </PropertyGroup>
  <Message Text="ENABLE_DEBUGGING = $(DebugVal)" />
</Target>

Inspiration from here and here

Community
  • 1
  • 1
stijn
  • 34,664
  • 13
  • 111
  • 163