I've created an MSI file with WiX. The source WiX file contains the version information like this:
<Product Id="..."
Name="..."
Language="1033"
Version="1.0.0.1"
Manufacturer="..."
UpgradeCode="...">
The MSI file seem to work OK: it installs, it uninstalls, it upgrades when I increase the version number, etc.
However, when I attempt to get the version information about this file by calling the MsiGetFileVersion() API, it returns error 1006 (ERROR_FILE_INVALID File does not contain version information.)
Hence my question: how to (programmatically, in C++) retrieve the version number of an MSI file? Or, to put it another way, where in the WiX file should the version information go in order to be retrievable via MsiGetFileVersion()?
More information: The same error occurs with MSI 3.0 on Windows XP and MSI 4.0 on Vista.
When you right-click an MSI file and then click properties, certain information is displayed on the summary tab. I would like to display the version number from the "product properties" in InstallShield.
In Visual Studio, open your solution, and add a WiX project to it: go to the Visual Studio main menu and click File -> Add -> New Project to open the Add New Project dialog. Choose the Setup Project item in the Windows Installer XML node, specify the project name and click OK.
The WiX tools follow the traditional compile and link model used to create executables from source code. At build time, the WiX source files are validated against the core WiX schema, then processed by a preprocessor, compiler, and linker to create the final result.
For reference, here's a VBscript example that I'm using in my build process to grab such prior to creating a boostrapper.
Dim installer, database, view, result
Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase ("my.msi", 0)
Dim sumInfo : Set sumInfo = installer.SummaryInformation("my.msi", 0)
sPackageCode = sumInfo.Property(9) ' PID_REVNUMBER = 9, contains the package code.
WScript.Echo getproperty("ProductVersion")
WScript.Echo getproperty("ProductVersion")
WScript.Echo sPackageCode
WScript.Echo getproperty("ProductName")
Function getproperty(property)
Set view = database.OpenView ("SELECT Value FROM Property WHERE Property='" & property & "'")
view.Execute
Set result = view.Fetch
getproperty = result.StringData(1)
End Function
Just for completeness sake, ::MsiGetFileVersion() is a function that reads the version resource information from a PE file (.exe or .dll) the same way the Windows Installer does. That is important for build tools (such as the WiX toolset) to use so they populate the File/@Version information correctly. It will not get you the version information out of an MSI. As @sascha shows you could query the Property table for the "ProductVersion" or you could use the ::MsiGetProductProperty() which will do the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With