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

查看:114
本文介绍了使用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天全站免登陆