MSBuild 筛选条件文件的 ItemGroup [英] MSBuild Filtering ItemGroup of files with condition

查看:119
本文介绍了MSBuild 筛选条件文件的 ItemGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这感觉很简单,但我无法让它工作.

This feels like it's so simple, but I cannot get it to work.

我想要实现的只是一个过滤后的嵌入资源列表.我尝试了各种方法,但似乎都做对了.

All I'm trying to achieve is a filtered list of the embedded resources. I've tried various approaches but I can't seem to get it right.

以下是我认为正确的解决方案:

Here's what I thought was the right solution:

<ItemGroup>
  <AllEmbeddedResources Include="@(EmbeddedResource)" Condition="$(FullPath.Contains('Change')"/>
</ItemGroup>

编辑...澄清一下,结果是没有条件的,列表是所有嵌入的资源,有条件的,组为空.

Edit... To clarify, the results are without the condition, the list is all embedded resources, with the condition, the group is empty.

我在目标的内部和外部都尝试过这个,我尝试在一个组中获取完整列表,然后在一个单独的组中进行过滤.我知道我只是误解了 msbuild 语法的一些基本部分,我似乎无法解决.期待看到我愚蠢的错误!

I've tried this inside and outside of target's, and I've tried getting the full list in one group, and then filtering in a separate group. I know I'm just misunderstanding some fundamental part of msbuild syntax, I just can't seem to work it out. Looking forward to being shown my stupid mistake!

推荐答案

在目标内部,这可以使用项目的批处理语法和使用 System.String.Copy 方法来完成在字符串上调用实例函数:

Inside a target, this can be done using the batching syntax for items and using the System.String.Copy method to be able to call instance functions on the string:

<Target Name="ListAllEmbeddedResources">
  <ItemGroup>
    <AllEmbeddedResources Include="@(EmbeddedResource)" Condition="$([System.String]::Copy(%(FullPath)).Contains('Change'))" />
  </ItemGroup>
  <Message Importance="high" Text="AllEmbeddedResources: %(AllEmbeddedResources.Identity)" />
</Target>

请注意,此语法仅适用于目标内部,而不适用于静态评估(直接在 节点下的项目组).

Note that this syntax only works inside a target and not during static evaluation (item group directly under the <Project> node).

这篇关于MSBuild 筛选条件文件的 ItemGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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