我具有以下MSBuild .proj文件内容:
<ItemGroup>
<Exclude Include="*2.*"></Exclude>
</ItemGroup>
<ItemGroup>
<!-- I have 3 files in the current directory: File1.cpp, File2.cpp and File3.cpp -->
<ModuleInclude Include="*.cpp" Exclude="@(Exclude)"></ModuleInclude>
<!-- I have 3 files in the Subfolder directory: eFile1.h, eFile2.h and eFile3.h -->
<ModuleInclude Include="Subfolder\*.h" Exclude="@(Exclude->'Subfolder\%(identity)')"></ModuleInclude>
</ItemGroup>
<Target Name="Default">
<Message Text="ModuleIncludes: %(ModuleInclude.identity)" />
<Message Text="Excluded Items: @(Exclude)" />
<Message Text="Excluded Subfolder Items: @(Exclude->'Subfolder\%(identity)')" />
</Target>
我看到以下输出:
ModuleIncludes: File1.cpp
ModuleIncludes: File3.cpp
ModuleIncludes: Subfolder\eFile1.h
ModuleIncludes: Subfolder\eFile2.h
ModuleIncludes: Subfolder\eFile3.h
Excluded Items: File2.cpp
Excluded Subfolder Items: Subfolder\File2.cpp
我真正需要的是包含以下子文件夹文件
ModuleIncludes: Subfolder\eFile1.h
ModuleIncludes: Subfolder\eFile3.h
因此,排除的子文件夹项目应为:
Excluded Subfolder Items: Subfolder\eFile2.h
要获得这样的输出,我需要表达式
Subfolder\*2.*
我正在使用的语法
@(Exclude->'Subfolder\%(identity)')
没有给我我需要的东西。 正确的语法是什么?还是不可能?
答案 0 :(得分:0)
如果要将通配符作为文本处理,请使用属性代替项目:
<PropertyGroup>
<FileExcludes>*2.*</FileExcludes>
</PropertyGroup>
<ItemGroup>
<ModuleInclude Include="*.cpp" Exclude="$(FileExcludes)"></ModuleInclude>
<ModuleInclude Include="Subfolder\*.h" Exclude="Subfolder\$(FileExcludes)"></ModuleInclude>
</ItemGroup>
您甚至可以在此处使用与子文件夹无关的匹配模式:
<PropertyGroup>
<FileExcludes>**\*2.*</FileExcludes>
</PropertyGroup>
<ItemGroup>
<ModuleInclude Include="*.cpp" Exclude="$(FileExcludes)"></ModuleInclude>
<ModuleInclude Include="Subfolder\*.h" Exclude="$(FileExcludes)"></ModuleInclude>
</ItemGroup>
如果您真的需要它作为列表来放置非本地文件夹,请使用元数据项:
<PropertyGroup>
<FileExclude Include="2">
<Pattern>**\*2.*</Pattern>
</FileExclude>
</PropertyGroup>
<ItemGroup>
<ModuleInclude Include="*.cpp" Exclude="@(FileExclude)"></ModuleInclude>
<ModuleInclude Include="..\shared-folder\*.h" Exclude="@(FileExclude->'shared-folder\%(Pattern)')"></ModuleInclude>
</ItemGroup>