文件包含/排除基于子文件夹名称

时间:2016-05-11 18:00:32

标签: msbuild msbuild-4.0

我有以下文件结构:

\RootFolder\
\RootFolder\SubFolder1\
\RootFolder\SubFolder1\SubfolderA\
\RootFolder\SubFolder1\SubfolderA\bin\
\RootFolder\SubFolder1\SubfolderA\bin\MySameNameFile1.txt
\RootFolder\SubFolder1\SubfolderA\bin\MySameNameFile2.txt
\RootFolder\SubFolder1\SubfolderA\bin\MySameNameFile3.txt
\RootFolder\SubFolder1\SubfolderA\bin\DontWantFile.txt
\RootFolder\SubFolder1\SubfolderA\obj\
\RootFolder\SubFolder1\SubfolderA\obj\MySameNameFile1.txt
\RootFolder\SubFolder1\SubfolderA\obj\MySameNameFile2.txt
\RootFolder\SubFolder1\SubfolderA\obj\MySameNameFile3.txt


\RootFolder\SubFolder2\
\RootFolder\SubFolder2\SubfolderB\
\RootFolder\SubFolder2\SubfolderB\bin\
\RootFolder\SubFolder2\SubfolderB\bin\MySameNameFile1.txt
\RootFolder\SubFolder2\SubfolderB\bin\MySameNameFile2.txt
\RootFolder\SubFolder2\SubfolderB\bin\MySameNameFile3.txt
\RootFolder\SubFolder2\SubfolderB\bin\DontWantFile.txt

\RootFolder\SubFolder2\SubFolder2\obj\
\RootFolder\SubFolder2\SubfolderB\obj\MySameNameFile1.txt
\RootFolder\SubFolder2\SubfolderB\obj\MySameNameFile2.txt
\RootFolder\SubFolder2\SubfolderB\obj\MySameNameFile3.txt


\RootFolder\SubFolder3\
\RootFolder\SubFolder3\SubfolderC\
\RootFolder\SubFolder3\SubfolderC\bin\
\RootFolder\SubFolder3\SubfolderC\bin\MySameNameFile1.txt
\RootFolder\SubFolder3\SubfolderC\bin\MySameNameFile2.txt
\RootFolder\SubFolder3\SubfolderC\bin\MySameNameFile3.txt
\RootFolder\SubFolder3\SubfolderC\bin\DontWantFile.txt

\RootFolder\SubFolder3\SubfolderC\obj\
\RootFolder\SubFolder3\SubfolderC\obj\MySameNameFile1.txt
\RootFolder\SubFolder3\SubfolderC\obj\MySameNameFile2.txt
\RootFolder\SubFolder3\SubfolderC\obj\MySameNameFile3.txt

我试图获得所有" MySameNameFile *。*"文件,但不是\ obj \目录中的文件。

我尝试过的事情:

<PropertyGroup>
    <MyRootFolderVariable>.\RootFolder\</MyRootFolderVariable>
</PropertyGroup>

<Target Name="MyTarget">

    <ItemGroup>
        <MyExcludeFiles Include="$(MyRootFolderVariable)\**\obj\*.*" />
    </ItemGroup>

    <ItemGroup>
        <MyIncludeFiles Include="$(MyRootFolderVariable)\**\*MySameNameFile*.txt" Exclude="@(MyExcludeFiles)" />
    </ItemGroup>  

    <PropertyGroup>
        <BinFilesButNoObjFiles>@(MyIncludeFiles->'&quot;%(fullpath)&quot;' , ' ')</BinFilesButNoObjFiles>
    </PropertyGroup>  

    <Message Text="BinFilesButNoObjFiles=$(BinFilesButNoObjFiles)"/>
    <Message Text="   "/>
    <Message Text="   "/>

</Target>

我之后的档案:

\RootFolder\SubFolder1\SubfolderA\bin\MySameNameFile1.txt
\RootFolder\SubFolder1\SubfolderA\bin\MySameNameFile2.txt
\RootFolder\SubFolder1\SubfolderA\bin\MySameNameFile3.txt

\RootFolder\SubFolder2\SubfolderB\bin\MySameNameFile1.txt
\RootFolder\SubFolder2\SubfolderB\bin\MySameNameFile2.txt
\RootFolder\SubFolder2\SubfolderB\bin\MySameNameFile3.txt

\RootFolder\SubFolder3\SubfolderC\bin\MySameNameFile1.txt
\RootFolder\SubFolder3\SubfolderC\bin\MySameNameFile2.txt
\RootFolder\SubFolder3\SubfolderC\bin\MySameNameFile3.txt

1 个答案:

答案 0 :(得分:0)

我很亲密。请注意下面答案中的第二个“**”。

 <MyExcludeFiles Include="$(MyRootFolderVariable)\**\obj\**\*.*" />