|
Automatically Updating Build Version Number (MSVC)
Submitted by |
I have spent today looking for a way to automatically
update the built number of an application after a
succesful built. I started out naively assuming that there
would be a simple checkbox labeled 'Increment Build
Number Automaticaly'....silly me ;)
However, after searching around on the web I did find
some solutions to the problem. Most of them had a
few problems however:
You needed one or more extra .h files
You needed to invoke a special command to build
Built numbers were also incremented on unsuccesful
builts
Difficult to implement (for me at least)
However, I did find some good reference materials
that bypassed some of these problems. One is a
VBScript from Thomas Mahler, found at CodeGuru (link)
Which doesn't need extra .h files, but suffers from the
other two problems. The other is a Microsoft
Knowledge Base article about built numbers,
(link)
Which does need .h files but solves the other two.
Combining them was easy, so I now post a macro that
solves all three problems and should be easy to use:
sub Application_BuildFinish(nNumErrors, nNumWarnings)
'DESCRIPTION: Event to increase version counter in rc script after
succesfull builds. (c)'2002 by Stijn de Witt, modified from code by Th. Mahler, 1998
if nNumErrors <= 0 then
'OPEN THE PROJECTS RESOURCE SCRIPT
Documents.Open (ActiveProject.Name + ".rc"), "Text"
Windows(ActiveProject.Name + ".rc").Active = True
'SELECT BUILD NUMBER FROM PRODUCTVERSION
' Find line with PRODUCTVERSION Information
ActiveDocument.Selection.FindText "PRODUCTVERSION", dsMatchForward + dsMatchFromStart + dsMatchCase
' Move to eol
ActiveDocument.Selection.EndOfLine
' Mark Build Number
ActiveDocument.Selection.WordLeft 1
' Store in strVersion
Dim strVersion
strVersion = ActiveDocument.Selection.Text
'INCREASE BUILD NUMBER AND REPLACE OLD ONE
ActiveDocument.Selection.ReplaceText strVersion , strVersion+1
strVersion = strVersion + 1
'NOW DO THE SAME FOR FILEVERSION, ProductVersion AND FileVersion
'START WITH FILEVERSION
' Find line with FILEVERSION Information
ActiveDocument.Selection.FindText "FILEVERSION", dsMatchForward + dsMatchFromStart + dsMatchCase
' Move to eol
ActiveDocument.Selection.EndOfLine
' Mark Build Number
ActiveDocument.Selection.WordLeft 1
' Store in strTmp
Dim strTmp
strTmp = ActiveDocument.Selection.Text
' Replace old build number with new
ActiveDocument.Selection.ReplaceText strTmp , strVersion
'THEN UPDATE ProductVersion
' Find line with ProductVersion Information
ActiveDocument.Selection.FindText "VALUE ""ProductVersion"",", dsMatchForward + dsMatchFromStart + dsMatchCase
' Move to eol and then to end of build number
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.CharLeft dsMove, 3
ActiveDocument.Selection.WordLeft 1
' Store in strTmp
strTmp = ActiveDocument.Selection.Text
' Replace old build number with new
ActiveDocument.Selection.ReplaceText strTmp , strVersion
'FINALLY UPDATE FileVersion
' Find line with FileVersion Information
ActiveDocument.Selection.FindText "VALUE ""FileVersion"",", dsMatchForward + dsMatchFromStart + dsMatchCase
' Move to eol and then to end of build number
ActiveDocument.Selection.EndOfLine
ActiveDocument.Selection.CharLeft dsMove, 3
ActiveDocument.Selection.WordLeft 1
' Store in strTmp
strTmp = ActiveDocument.Selection.Text
' Replace old build number with new
ActiveDocument.Selection.ReplaceText strTmp , strVersion
'CLOSE FILE, BUILD APP AND SAVE ALL DOCUMENTS
' Close RC file
ActiveDocument.Close()
' Save documents
Documents.SaveAll true
PrintToOutputWindow "Successfully built " & ActiveProject.Name & "version " & strVersion
end if
end sub
The macro hooks to an event that MSVC fires after the
built is completed. It checks if the built was succesful, then
opens the project resource file to update the version
information. It still suffers from the minor glitch that if the
resource file is already open, a popup box appears saying
that it will be closed. This could probably be solved to, so
please let me know if you do.
|
The zip file viewer built into the Developer Toolbox made use
of the zlib library, as well as the zlibdll source additions.
|