如何从 MSBuild 中的 ItemGroup 构建 PropertyGroup 条目? [英] How to build a PropertyGroup entry from an ItemGroup in MSBuild?

查看:35
本文介绍了如何从 MSBuild 中的 ItemGroup 构建 PropertyGroup 条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 MSBuild 非常陌生,无法弄清楚如何从条件部分构建 PropertyGroup 条目.

I'm very new to MSBuild and am having trouble figuring out how to construct a PropertyGroup entry from conditional parts.

这是我所拥有的,但不起作用:

Here's what I have, which is not working:

<ItemGroup>
    <CompilerDirective Include="DEBUG_PARANOID" Condition=" '$(SomeFlag)' == 'true' "/>
    <CompilerDirective Include="DEBUG"/>
    <CompilerDirective Include="TRACE"/>
</ItemGroup>

<PropertyGroup>
    ...
    <DefineConstants>@(CompilerDirective)</DefineConstants>
    ...
</PropertyGroup>

如果 SomeFlag 设置为真,我希望定义的常量显示为 DEBUG_PARANOID;DEBUG;TRACE,否则省略 DEBUG_PARANOID.顺便说一下,这是针对 .csproj 的.

I'd like the constants that get defined to show up as DEBUG_PARANOID;DEBUG;TRACE if SomeFlag is set true, leaving out DEBUG_PARANOID if not. This is for a .csproj, by the way.

如果我用消息任务打印出@(CompilerDirective),它就可以工作.

If I print out @(CompilerDirective) with a message task, it works.

我的问题是如何在 PropertyGroup 条目中进行这项工作?

My question is how to make this work inside of a PropertyGroup entry?

推荐答案

以上内容有效.我跑了这个:

What you have above works. I ran this:

<Target Name="Test">
  <ItemGroup>
      <CompilerDirective Include="DEBUG_PARANOID"
        Condition=" '$(SomeFlag)' == 'true' "/>
      <CompilerDirective Include="DEBUG"/>
      <CompilerDirective Include="TRACE"/>
  </ItemGroup>
  <PropertyGroup>
    <DefineConstants>@(CompilerDirective)</DefineConstants>
  </PropertyGroup>
  <Message Text="$(DefineConstants)" />
</Target>

并得到正确的输出调试;跟踪或者DEBUG_PARANOID;调试;跟踪取决于财产的价值.这在哪些方面对您不起作用?

and got the proper output DEBUG;TRACE or DEBUG_PARANOID;DEBUG;TRACE depending on the value of the property. In what manner does this not work for you?

这篇关于如何从 MSBuild 中的 ItemGroup 构建 PropertyGroup 条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆