MSBUILD Splitting text file into lines

岁酱吖の 提交于 2020-01-03 05:51:08

问题


Note that I have already went through:

Is there a way to print a new-line when using <Message...>?

Read text file and split every line in MSBuild

But for some strange reason I can't make it work.

I have:

        <ReadLinesFromFile File="$(OutputPath)myfile.log">
            <Output PropertyName="FileOutput" TaskParameter="Lines" />
        </ReadLinesFromFile>

        <Message Text="$(FileOutput)"/>

-- This works, entire file content is shown on the screen.

Now I would like for each line in that file to report a warning/error.

    <ItemGroup>
        <SplitVersion Include="$(FileOutput.Split('%0A%0D'))"/>
    </ItemGroup>

    <Warning Text="%(SplitVersion.Identity)" /> 

Whatever combination I try in Split (e.g. \n, \r\n, %0A etc.) I get only one warning instead of getting one warning per line.


回答1:


You are storing the lines in a property (typo maybe? Anyway I didn't even know was possible until now - it is also not mentioned in the documentation), store them in an item list instead and you'll get the lines, split already by ReadLinesFromFile so you don't have to bother with it, and after all that's the main way it is supposed to be used. Note the ItemName where you had PropertyName:

<ReadLinesFromFile File="$(OutputPath)myfile.log">
  <Output ItemName="FileOutput" TaskParameter="Lines" />
</ReadLinesFromFile>
<Message Text="%(FileOutput.Identity)"/>


来源:https://stackoverflow.com/questions/33963853/msbuild-splitting-text-file-into-lines

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