Version Info manipulations on compile-time

From NSIS Wiki
Jump to navigationJump to search
Author: Lion (talk, contrib)


The technique described on this page can now be accomplished in NSIS 3 without using 3rd-party tools by using !getdllversion and VIProductVersion/VIAddVersionKey


Description

Recently, I was faced with the problem of automating my scripts on compile-time. I first started with the VersionInfo automation.

Examples

Before the change

This is how it WAS before (I had to change version variables manually before each compile):

;...
!define _VERSION "1.2.3.4"
;...
;from {NSISDIR}\Examples\VersionInfo.nsi
VIProductVersion "${_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${_PRODUCT}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "..."
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${_VERSION}"
VIAddVersionKey /LANG=${LANG_ENGLISH} "InternalName" "FileSetup.exe"
;...

After the change

And this is how it is NOW:

!define _RESHACKER "C:\WinApps\NSIS2\ResHacker\ResHacker.exe"
 
Var _VERSION
 
Function InitVersion
  !execute '"${_RESHACKER}" -extract ${_SRCDIR}\File.exe, FileVersionInfo.rc, versioninfo,1,'
 
  Push 'VALUE "FileVersion", "'
  Push '"'
  Push 'C:\WinApps\NSIS2\_Production\FileVersionInfo.rc'
  Call GetBetween
  Pop "$_VERSION"
FunctionEnd
 
Function .onInit
  ;...
  call InitVersion
  ;...
FunctionEnd
 
;...
  !execute '"${_RESHACKER}" -extract ${_SRCDIR}\File.exe, FileVersionInfo.res, versioninfo,1,'
  !packhdr tmp.dat '"${_RESHACKER}" -addoverwrite tmp.dat, tmp.dat, FileVersionInfo.res, versioninfo,1,'
  !echo "VersionInfo added"
;...

In the first case, ResHacker is used to extract decompiled VersionInfo resource from .exe to a text .rc file, the I have to parse it to get version in a string "x.x.x.x" form. Personaly, I'm using it e.g. in the installer's window caption (Caption "${_PRODUCT} v${_VERSION} Setup").

And the second case where I need ResHacker again is just duplicating the VersionInfo resource from my File.exe to FileSetup.exe.

This was inspired by these articles (listed in order of occurrence on my display :))

About the Author

I'm a newbie to NSIS's depths so please do not blame me out of hand if you found an error or smth else not-good here.

Let the NSIS be with you!

Lion