开发者

batching file strings by itemgroup metadata in msbuild

开发者 https://www.devze.com 2023-03-02 17:22 出处:网络
How to batch strings from开发者_JAVA技巧 files by the metadata passed in itemgroup along with the file names?

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.).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号