I have a text file with a numeric value in it (say 1). I open and read the file using:
<BuildVersionFile Include="$(MSBuildProjectDirectory)\BuildNumber.txt"/>
<Target Name="ReadReleaseNotes">
<ReadLinesFromFile
File="@(BuildVersionFile)" >
<Output
TaskParameter="Lines"
ItemName="Build
Version"/>
</ReadLinesFromFile>
I want to increase the value of BuildVersion and write it back to the txt file. How can I do this math?
For MSBuild >= 4.0 you can perform maths against properties.
For MSBuild < 4.0, without writing your own custom task or using an existing addin, I'm not aware of a way of doing this to a plain text file. If you are stuck with an old version, and wanted to change from a plain text file to AssemblyInfo.cs file, you could use the auto-incrementing feature of AssemblyVersion
and/or AssemblyFileVersion
, replacing a version part with *. More details here.
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