Build number tracking in DOS

Got a build project running in DOS and need to generate a build number?

Building the Dungeon Raider project has been a mission and when using build tools locally it can be a problem keeping track of version numbers. Rather than doing this manually here is a simple script that automatically updated a build number every time it is executed:

@echo off
echo Set build version
set /p BuildTemplate=<BuildVersionTemplate.txt
set /p BuildCount=<BuildCount.txt
set /a BuildCount=%BuildCount%+1
echo %BuildCount% > BuildCount.txt
set BuildString=%BuildTemplate:build=%%BuildCount%  
echo Setting build version: %BuildString%
echo %BuildString% > version.txt
echo %date% %time% %BuildString% >> BuildVersion.log

The following files are used by this script:

File namePurposeRecommended default
BuildVersionTemplate.txtContains the format of the final string. The reserved word ‘build’ is replaced in the final version string1.build
BuildCount.txtContains the number of times the script was executed1
BuildVersion.logLog file showing the date/time and version numbers<will be generated>
version.txtThe output file that can be consumed by your project<will be generated>

To use save the batch file as BuildVersion.bat and set the BuildVersionTemplate.txt an d BuildCount.bat as above.

Every time you run the batch file from now on it will update the version.txt file with the following content:

Run 1: 1.1

Run 2: 1.2

Run 3: 1.3 etc…

If there is a major version change then you could update the BuildVersionTemplate.txt to be 2.<build> and reset the BuildCount.txt to 0 The result would then be:

Run 1: 2.1

Run 2: 2.2

Run 3: 2.3

Storing these files in source control should allow you to store the current status of the build version so you remain consistant.

The log file contains a list of build runs:

15/10/2024 12:53:15.32 1.15   
15/10/2024 12:53:20.60 1.16   

Which allows for a track of the build runs against a project.

Why?

The intention of this is to generate a simple version.txt file that can be included within a project. In this particular case it will be part of the build pipeline to generate a version.txt that will be loaded by the project and displayed on screen. In this particular case (Dungeon Raider) it removes some of the complexity of the build version tracking.

Leave a Reply

Your email address will not be published. Required fields are marked *