batching file strings by itemgroup metadata in msbuild
How to batch strings from开发者_JAVA技巧 files by the metadata passed in itemgroup along with the file names?
Here is what i've got so far, but can't figure out how to pass initial itemgroups metadata Level
to the resulting item group Lines
:
<ItemGroup>
<LogFile Include="1.log">
<Level>Warning</Level>
</LogFile>
<LogFile Include="2.log">
<Level>Warning</Level>
</LogFile>
<LogFile Include="3.log">
<Level>Error</Level>
</LogFile>
<ItemGroup>
<ReadLinesFromFile
File="@(LogFile)" >
<Output
TaskParameter="Lines"
ItemName="LogMessage"/>
</ReadLinesFromFile>
<Message Text="%(LogMessage.Identity)" />
What i want to get is:
Warning: (lines from 1.log>
Warning: (lines from 2.log>
Error: (lines from 3.log)
where Warning and Error is given by %(LogFile.Level)
It seems that what you are trying to achieve is not possible due to the fact that <ReadLinesFromFile>
doesn't accept an ITaskItem Collection @(LogFile)
as its File
input and you'll have to batch on Task level %(LogFile.Identity)
<Project ToolsVersion="4.0" DefaultTargets="PrintOut">
<ItemGroup>
<LogFile Include="1.log">
<Level>Warning</Level>
</LogFile>
<LogFile Include="2.log">
<Level>Warning</Level>
</LogFile>
<LogFile Include="3.log">
<Level>Error</Level>
</LogFile>
</ItemGroup>
<Target Name="ReadLogs">
<ReadLinesFromFile File="%(LogFile.Identity)">
<Output TaskParameter="Lines" ItemName="LogMessage" />
</ReadLinesFromFile>
</Target>
<Target Name="PrintOut" DependsOnTargets="ReadLogs">
<Message Text="%(LogMessage.Identity)" />
</Target>
</Project>
There are some examples about Item Metadata in Task Batching but they all deal with Tasks that can handle ITaskItem Collection input (like Copy
etc.).
精彩评论