任务MSBuild如何遍历文件 [英] How does task MSBuild loop over files
问题描述
<Target Name="Build">
...
<MSBuild
Projects="$(MSBuildProjectFile)"
Condition="'@(FilesToCompile)' != ''"
Targets="buildcpp"
Properties="CPPFILE=%(FilesToCompile.FullPath);OBJFILE=$(ObjectFolder)\%(FilesToCompile.Filename).doj;IncludeDirs=$(IncludeDirs)"
/>
FilesToCompile
是所有.cpp
文件的ItemGroup
.
当我查看构建日志时,它显示了目标buildcpp
正在为CPPFILE
中的每个文件运行.
When I look at the build log, it shows the target buildcpp
being run for each of the files in CPPFILE
.
I understand that is what I logically want to happen but my question is, what rule of element <MSBuild>
or the MSBuild
schema causes task MSBuild
to be executed for each value of CPPFILE
?
简而言之,在文档中它指出将要发生的事情?
In short, where in the documentation does it state that is what will happen?
我想传递一次整个ItemGroup
,而不是为每个项目一次调用MSBuild
目标.
I want to pass in an entire ItemGroup
once instead of calling the MSBuild
target once for each item.
推荐答案
基于msbuild的概念称为批处理"-在您的情况下,是任务批处理(请参阅
The msbuild concept this is based on is called "batching" - in your case task batching (see MSBuild's task batching documentation).
任何包含对项目组的%()
引用的任务都将被分成共享相同元数据的批处理,并且该任务将对每个批处理执行一次.使用诸如Identity
或FullPath
之类的内置元数据时,这实际上意味着为所有项目执行此任务",尽管也可能存在更复杂的用例.
Any task that contains a %()
reference to an item group will be split up into batches that share the same metadata and the task will be executed once for each batch. When using built-in metadata like Identity
or FullPath
, this essentially means "execute this task for ever item", though there can also be more complex use cases.
这篇关于任务MSBuild如何遍历文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!