MSBUILD将文本文件分成几行 [英] MSBUILD Splitting text file into lines

查看:85
本文介绍了MSBUILD将文本文件分成几行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,我已经经历过:

Note that I have already went through:

有没有办法在使用< Message ...>时打印换行符?

读取文本文件并拆分MSBuild中的每一行

但是出于某些奇怪的原因,我无法使其正常工作.

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

我有:

        <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)" /> 

无论我在拆分中尝试使用哪种组合(例如\ n,\ r \ n,%0A等),我都只会收到一条警告,而不是每行收到一条警告.

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.

推荐答案

您正在将行存储在属性中(可能是打字错误?无论如何,直到现在我什至都不知道有可能-文档),而是将其存储在项目列表中, ,已经由ReadLinesFromFile进行了拆分,因此您不必理会它,毕竟这是应该使用它的主要方式.注意您在PropertyName所在的ItemName:

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)"/>

这篇关于MSBUILD将文本文件分成几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆