是否有一个MSBuild任务可以将行写入文件的“开始"? [英] Is there an MSBuild task that will write lines to the *start* of a file?

查看:64
本文介绍了是否有一个MSBuild任务可以将行写入文件的“开始"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WriteLinesToFile更新更改日志文件(txt).它将文本附加到文件末尾.理想情况下,我希望能够将更改写入此文件的开始.

I'm using a WriteLinesToFile to update a change log file (txt). It appends the text to the end of the file. Ideally, I'd like to be able to write the changes to the start of this file.

是否有一个简单的任务(例如,在社区"或扩展"包中)完成此任务?

Is there a simple task (e.g. in the Community or Extension packs) that does this?

推荐答案

在自定义任务包中没有看到类似的东西.

I haven't seen something like that in the custom task pack.

您可以使用ReadLinesFromFileWriteLinesToFile作弊:

<PropertyGroup>
  <LogFile>log.txt</LogFile>
</PropertyGroup>

<ItemGroup>
  <Log Include="Line1"/>
  <Log Include="Line2"/>
</ItemGroup>

<Target Name="WriteFromStart">
  <ReadLinesFromFile File="$(LogFile)" Condition="Exists('$(LogFile)')">
    <Output TaskParameter="Lines" ItemName="Log"/>
  </ReadLinesFromFile>

  <WriteLinesToFile File="$(LogFile)" 
                    Lines="@(Log)" 
                    Condition="@(Log) != '' And (@(Log) != '\r\n' Or @(Log) != '\n')"
                    Overwrite="true">
  </WriteLinesToFile>
</Target>

或者您可以创建一个自定义任务.

Or you could create a custom task.

这篇关于是否有一个MSBuild任务可以将行写入文件的“开始"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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