How does task MSBuild loop over files

冷暖自知 提交于 2020-01-04 05:58:11

问题


<Target Name="Build">
...

    <MSBuild
            Projects="$(MSBuildProjectFile)"
            Condition="'@(FilesToCompile)' != ''"
            Targets="buildcpp"
            Properties="CPPFILE=%(FilesToCompile.FullPath);OBJFILE=$(ObjectFolder)\%(FilesToCompile.Filename).doj;IncludeDirs=$(IncludeDirs)"
        />

FilesToCompile is an ItemGroup of all .cpp files.

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?

I want to pass in an entire ItemGroup once instead of calling the MSBuild target once for each item.


回答1:


The msbuild concept this is based on is called "batching" - in your case task batching (see MSBuild's task batching documentation).

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.



来源:https://stackoverflow.com/questions/46590580/how-does-task-msbuild-loop-over-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!