【问题标题】:MS Build: Access compiler settings in a subsequent taskMSBuild:在后续任务中访问编译器设置
【发布时间】:2011-01-18 08:25:04
【问题描述】:

我正在编写自己的 MS 构建脚本,并将其导入项目文件 (*.vcxproj)

我想根据动态使用的 C 运行时有条件地执行任务。我尝试了以下方法:

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

但是 $(RunitmeLibrary) 不是属性,而是 ClCompile 的参数。

有没有其他方法可以编写一个条件来检查运行时是动态喜欢还是静态喜欢?

问候

【问题讨论】:

    标签: visual-studio-2010 msbuild


    【解决方案1】:

    您要查找的值是 ClCompile 项组的元数据。使用这个:

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

    我将此添加到 vcxproj 的底部以查看当前设置是什么:

     <Target Name="BeforeClCompile">
        <Message Text="BeforeCompile: RuntimeLibrary=[%(ClCompile.RuntimeLibrary)]" Importance="high" />
     </Target>
    

    【讨论】:

    • 谢谢,这正是我想要的。除了在 Condition 中访问 %(ClCompile.RuntimeLibrary) 似乎是非法的。 (错误代码 MSB4191:在此条件 '%(ClCompile.RuntimeLibrary)' == 'MultiThreadedDLL' 中不允许在位置 1 引用自定义元数据“RuntimeLibrary”。我通过创建一个存储此自定义元数据的值并在条件中使用属性。%(ClCompile.RuntimeLibrary)
    • @niks 有没有办法在目标之外定义这个属性?当我这样做时,%(...) 不会被评估,它仍然是以百分号开头的相同字符串。
    • 要完成这个答案,这会导致正确的方向here 是一个详细的答案,即使在构建后事件中也可以通过 $(RuntimeLibrary) 作为示例来获取参数。在 VS 2015 中,我必须编写 @(ClCompile->'%(RuntimeLibrary)'->Distinct()) 才能获得 ItemGroup 的一个结果
    猜你喜欢
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多