MS Build:在后续任务中访问编译器设置

3

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

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

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

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

是否有其他方法来编写一个条件,检查运行时是动态链接还是静态链接?

敬礼

1个回答

4
你要查找的值是ClCompile项目组的元数据。请使用以下内容:
Condition=" '%(ClCompile.RuntimeLibrary)' == 'MultiThreadedDll' "

我在一个vcxproj文件的底部添加了以下内容,以查看当前设置:

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

2
谢谢,这正是我在寻找的。除了似乎无法在条件语句中访问%(ClCompile.RuntimeLibrary)。 (错误代码MSB4191:不允许在此条件“%(ClCompile.RuntimeLibrary)”== 'MultiThreadedDLL'中引用自定义元数据“RuntimeLibrary”的引用位置1。)我已通过创建存储此自定义元数据值的属性并在条件中使用该属性来解决此问题。<PropertyGroup><RuntimeLibrary>%(ClCompile.RuntimeLibrary)</RuntimeLibrary></Property> - niks
2
@niks 有没有一种方法可以在目标之外定义此属性?当我这样做时,% (...) 不会被评估,它仍然是以百分号开头的相同字符串。 - Mikhail
为了完成这个答案,可以参考这里的详细答案,例如通过$(RuntimeLibrary)在Post-Build事件中获取参数。在VS 2015中,我需要编写以下代码才能获得ItemGroup的唯一结果: <PropertyGroup> <RuntimeLibrary>@(ClCompile->'%(RuntimeLibrary)'->Distinct())</RuntimeLibrary> </PropertyGroup> - 42tg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接