在 x64 系统上使用 CustomAction 构建 Visual Studio 2010 安装项目时,Visual Studio 包含错误版本InstallUtilLib.dll
:它安装 32 位 shim,这对于编译为 64 位的 CustomAction 不起作用(在我的情况下是一个要求,因为它取决于在 64 位本机 dll 上)。
安装这样的.msi
结果会导致System.BadImageFormat
异常。
根据这篇文章 (64-bit Managed Custom Actions with Visual Studio),解决方案是打开结果.msi
并orca.exe
替换二进制“InstallUtil”。
我想自动化这个。有任何想法吗?
编辑:根据 mohlsen 提供的答案,我在解决方案中添加了以下脚本(不是安装项目本身,因为添加到安装项目的文件进入 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
接下来,我编辑了设置项目属性:我将PostBuildEvent
属性设置为:
wscript.exe "$(ProjectDir)\..\Setup_PostBuildEvent_x64.vbs" $(BuiltOuputPath)
注意:在解决方案资源管理器中右键单击安装项目,然后选择“属性”会打开错误的对话框(“属性页”)。您需要“属性窗口”(CTRL+W、P)。