使用 MSBuild 在 ItemGroup 中创建文件夹列表 [英] Creating a list of Folders in an ItemGroup using MSBuild

查看:18
本文介绍了使用 MSBuild 在 ItemGroup 中创建文件夹列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 MSBuild 脚本中构建一个 ItemGroup,该脚本包含给定根"文件夹正下方的文件夹列表.所以 - 在这个例子中......

I'm trying to build an ItemGroup in an MSBuild script which contains a list of folders directly below a given 'Root' folder. So - in this example...

+ Root folder
---- Sub Folder 1
-------- Sub-Sub Folder 1
-------- Sub-Sub Folder 2
---- Sub Folder 2
---- Sub Folder 3

...我希望我的 ItemGroup 包含子文件夹 1"、子文件夹 2"和子文件夹 3".

... I would want my ItemGroup to contain "Sub Folder 1", "Sub Folder 2" and "Sub Folder 3".

层次结构中的任何一点都可能有许多文件,但我只对文件夹感兴趣.

There may be a number of files at any point in the hierarchy, but I'm only interested in the folders.

谁能帮忙!?

推荐答案

<PropertyGroup>
    <RootFolder>tmp</RootFolder>
</PropertyGroup>
<ItemGroup>
   <AllFiles Include="$(RootFolder)***"/>
   <OnlyDirs Include="@(AllFiles->'%(Directory)')"/>
</ItemGroup>

@(OnlyDirs) 可能包含重复项,因此您可以使用 RemoveDuplicatesTask :

@(OnlyDirs) might contain duplicates, so you could either use the RemoveDuplicatesTask :

<Target Name="foo">
   <RemoveDuplicates Inputs="@(OnlyDirs)">
      <Output TaskParameter="Filtered" ItemName="UniqueDirs"/>
   </RemoveDuplicates>
</Target>

或将 CreateItem 与 %(AllFiles.Identity) 或 msbuild 3.5 一起使用:

or use CreateItem with batching for %(AllFiles.Identity) or with msbuild 3.5:

<Target Name="foo">
   <ItemGroup>
      <UniqueDirs Include="%(AllFiles.Directory)"/>
   </ItemGroup>
</Target>

这篇关于使用 MSBuild 在 ItemGroup 中创建文件夹列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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