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.
You could cheat by using ReadLinesFromFile
and WriteLinesToFile
:
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With