7

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?

WendiKidd
  • 4,333
  • 4
  • 33
  • 50
Aref Karimi
  • 1,822
  • 4
  • 27
  • 46

1 Answers1

10

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.

Community
  • 1
  • 1
si618
  • 16,580
  • 12
  • 67
  • 84