When building a Visual Studio 2010 Setup project with a CustomAction on x64 systems, Visual Studio includes the wrong version of InstallUtilLib.dll
: It installs the 32bit shim, which will not work for CustomActions compiled as 64-bit (a requirement in my case, since it depends on 64-bit native dlls).
Installing such a .msi
results in the System.BadImageFormat
exception.
According to this post (64-bit Managed Custom Actions with Visual Studio), the solution is to open the resulting .msi
in orca.exe
and replace the binary "InstallUtil".
I'd like to automate this. Any ideas?
EDIT: based on the answer provided by mohlsen, I added following script to the solution (not the setup project itself, as files added to the setup project go into the msi...):
Option Explicit
rem -----------------------------------------------------------
rem Setup_PostBuildEvent_x64.vbs
rem
rem Patch an msi with the 64bit version of InstallUtilLib.dll
rem to allow x64 built managed CustomActions.
rem -----------------------------------------------------------
Const msiOpenDatabaseModeTransact = 1
Const msiViewModifyAssign = 3
rem path to the 64bit version of InstallUtilLib.dll
Const INSTALL_UTIL_LIB_PATH = "C:\Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtilLib.dll"
Dim installer : Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
Dim sqlQuery : sqlQuery = "SELECT `Name`, `Data` FROM Binary"
Dim database
Set database = installer.OpenDatabase(Wscript.Arguments(0), msiOpenDatabaseModeTransact)
Dim view : Set view = database.OpenView(sqlQuery)
Dim record : Set record = installer.CreateRecord(2)
record.StringData(1) = "InstallUtil"
view.Execute record
record.SetStream 2, INSTALL_UTIL_LIB_PATH
view.Modify msiViewModifyAssign, record
database.Commit
Set view = Nothing
Set database = Nothing
Next, I edited the Setup projects properties: I set the PostBuildEvent
property to:
wscript.exe "$(ProjectDir)\..\Setup_PostBuildEvent_x64.vbs" $(BuiltOuputPath)
Note: Right-clicking the setup project in solution explorer and then selecting "Properties" opens up the wrong dialog ("Property Pages"). You want the "Properties Window" (CTRL+W, P).