Itemgroup batch file metadata file strings in msbuild

How to set lines from files by metadata transferred in a group of elements along with file names?

Here is what I got so far, but I can’t understand how to transfer the metadata of the original elements of the Level group to the resulting group of Lines elements:

 <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:

 Warning: (lines from 1.log> Warning: (lines from 2.log> Error: (lines from 3.log) 

where Warning and Error are set by% (LogFile.Level)

+4
source share
1 answer

It seems that what you are trying to achieve is impossible because <ReadLinesFromFile> does not accept the ITaskItem @(LogFile) collection as its File tab, and you will have to execute the package at the %(LogFile.Identity) task level

 <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 several examples of item metadata in batch processing of tasks , but they all deal with tasks that can handle the input of the ITaskItem collection (for example, Copy , etc.) ..).

+2
source

All Articles