« Content-Adaptive Image Downscaling from Microsoft Research | Main | Interlude: Swan Lake through Zeno Music Visualizer »

Generating Auto-Incremented Version numbers with PowerShell

The code snippet below is something I had to write to simplify some build & deployment. Instead of me having to remember the latest version number to use, this PowerShell snippet lets me store the current version number as a Major.Minor.Patch (for example 1.2.3) one-line text file. The script updates the version number every time it is run.

Some techniques demonstrated:

  • Simple reading and writing of strings with Text files
  • Converting Strings to Integers and back
  • Splitting a string


Write-Host Calculate new version number

$curverfilename= "d:\curver.txt"

$curver = Get-Content $curverfilename | Out-String

Write-Host Current Version $curver

$tokens = $curver.Split(".")

$major = [int]( $tokens[0])

$minor = [int]( $tokens[1])

$patch = [int]( $tokens[2])

$new_patch = $patch + 1

$Version = ([string] $major)+"."+ ([string] $minor ) +"." + ([string]$new_patch)

Write-Host $Version

$Version | Out-File $curverfilename

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>