3

I need to increment version of an installer on every successful build. I have added a VBscript file and called it from a pre-build event. But am not able to get the actual result. my script is as under:

set a = wscript.arguments
if a.count = 0 then wscript.quit 1

'read and backup project file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(a(0))
s = f.ReadAll
f.Close
fbak = a(0) & ".bak"
if fso.fileexists(fbak) then fso.deletefile fbak
fso.movefile a(0), fbak

'find, increment and replace version number
set re = new regexp
re.global = true
re.pattern = "(""ProductVersion"" = ""8:)(\d+(\.\d+)+)"""
set m = re.execute(s)
v = m(0).submatches(1)
v1 = split(v, ".")
v1(ubound(v1)) = v1(ubound(v1)) + 1
vnew = join(v1, ".")
'msgbox v & " --> " & vnew
s = re.replace(s, "$1" & vnew & """")

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

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

'write project file
fnew = a(0)
set f = fso.CreateTextfile(fnew, true)
f.write(s)
f.close

and my Pre-build Event is as C:\Projects\VersionProject\myscript.vbs "$(ProjectDir)VersionProject.Installer.vdproj" .Any help appreciated.

user22197
  • 31
  • 4

2 Answers2

2

You'd need to go into the vdproj file and find the string of the form "ProductVersion" = "8:1.0.0"
and change the string from (say) 1.0.0 to 1.0.1.

However you're likely to get into trouble with updates if that's all you change. Note that when you increment the ProductVersion in the setup project it prompts to change ProductCode, and it will also change the PackageCode of the MSI file. So a safe change of the version involves all those things. For example, if you change only the version and attempt to reinstall the MSI it will fail with "Another version of this product is already installed". If you're unaware of these things, I suggest you familiarise yourself with how ProductCode, UpgradeCode, ProductVersion all interact, together with RemovePreviousVersions, and be aware that every new MSI created needs a new PackageCode.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
-3

Take a look at this. This Plugin allows you to set various options for the version number in your project.

And it does exactly what you need, auto increment the version number on each build . I've been using this for years and never had problems with it.

Update:

This Plugin only works if your project has an AssemblyInfo.cs

JoeJoe87577
  • 512
  • 3
  • 17