Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBUILD: Adding 1 to a variable?

Tags:

math

msbuild

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?

like image 915
Aref Avatar asked Dec 07 '11 05:12

Aref


1 Answers

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.

like image 71
si618 Avatar answered Sep 18 '22 12:09

si618