【问题标题】:Accessing PreProcessor definitions in MSBuild post-build events在 MSBuild 生成后事件中访问 PreProcessor 定义
【发布时间】:2016-02-28 10:15:46
【问题描述】:

给定一个如下的预处理器定义:

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

是否可以在 MSBuild 构建后事件期间确定 ENABLE_DEBUGGING 的值?

【问题讨论】:

    标签: visual-studio msbuild preprocessor post-build-event


    【解决方案1】:

    这可能是多种方法之一;仅当 ClCompile ItemGroup 包含项目时才有效,换句话说,当有要编译的文件并且它们都具有相同的 PreprocessorDefinitions 值时;它将在 DebugVal 属性中的ENABLE_DEBUGGING= 字符串之后找到的数字存储起来。:

    <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>
    

    来自herehere 的灵感

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-18
      • 2019-10-16
      相关资源
      最近更新 更多