Thursday 7 March 2013

ProductVersion update for MSI Projects

The script is written in VBScript and is quite simple.

  • read the project file passed in the command line, e.g., Setup.vdproj
  • backup the original file, just in case something goes wrong ;-)
  • find the version number
  • increment the version number
  • replace the version number with the new value
  • replace the product code with a new GUID
  • replace the package code with a new GUID
  • write the updated project file back to disk

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''  Set version number of an MSI setup project from assembly
''  and update relevant GUIDs
''  Chirag Patel /03/03/2013

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

set args = wscript.arguments
if args.count < 2 then wscript.quit 1

set fso = CreateObject("Scripting.FileSystemObject")
set regex = new regexp
regex.global = true

'read current version from Version.txt file...
set versionFile = fso.OpenTextFile(args(1))
strVerTxtFile = versionFile.ReadAll
versionFile.Close

'find version text from file
regex.pattern = "(\d+(\.\d+)+)"
set Matches = regex.Execute(strVerTxtFile)

'split version info text using '.' and create new one with major.minor.svnrev
versionArray = Split(Matches(0).submatches(0), ".")
myNewVer = versionArray(0) & "." & versionArray(1) & "." & versionArray(3)

'Wscript.Echo myNewVer

'read all text from .vdproj of Setup Project
Set vdProjFile = fso.OpenTextFile(args(0))
textOfSetupProj = vdProjFile.ReadAll
vdProjFile.Close

'find and replace version number in .vdproj file
regex.pattern = "(""ProductVersion"" = ""8:)(\d+(\.\d+)+)"""
textOfSetupProj = regex.replace(textOfSetupProj, "$1" & myNewVer & """")

'replace ProductCode
regex.pattern = "(""ProductCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
textOfSetupProj = regex.replace(textOfSetupProj, "$1" & guid & """")

'replace PackageCode
regex.pattern = "(""PackageCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
textOfSetupProj = regex.replace(textOfSetupProj, "$1" & guid & """")

'write back to .vbproj file with all the changes that we made above
set vdProjFileNew = fso.CreateTextfile(args(0), true)
vdProjFileNew.write(textOfSetupProj)
vdProjFileNew.close

Save IncrementSetupVersion.vbs 

For auto increment setup project version use scripts IncrementSetupVersion.vbs add them to pre-build events

first argument is setup project file, second is file with assembly version Example: "$(ProjectDir)..\SetupScript\IncrementSetupVersion.vbs" "$(ProjectDir)Setup.vdproj" "$(ProjectDir)..\version.txt"

0 comments:

Post a Comment