在 x64 系统上使用 CustomAction 构建 Visual Studio 2010 安装项目时,Visual Studio 包含错误版本的 InstallUtilLib.dll:它安装了 32 位 shim,这对于编译为64 位(对我来说是一个要求,因为它依赖于 64 位本机 dll).
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).
安装这样的 .msi 会导致 System.BadImageFormat 异常.
Installing such a .msi results in the System.BadImageFormat exception.
根据 这篇文章 (64-bit Managed Custom Actions with Visual Studio),解决方案是在 orca.exe 中打开生成的 .msi 并替换二进制文件InstallUtil".
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?
根据 mohlsen 提供的答案,我在解决方案中添加了以下脚本(不是安装项目本身,因为添加到安装项目的文件会进入 msi...):
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:WindowsMicrosoft.NETFramework64v2.0.50727InstallUtilLib.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 属性设置为:
Next, I edited the Setup projects properties: I set the PostBuildEvent property to:
wscript.exe "$(ProjectDir)..Setup_PostBuildEvent_x64.vbs" $(BuiltOuputPath)注意:在解决方案资源管理器中右键单击安装项目,然后选择属性"打开错误的对话框(属性页").你想要属性窗口"(CTRL+W, P).
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).
推荐答案不确定你想如何自动化,通过脚本、代码等.但无论如何,这个功能都可以通过 Windows Installer SDK,我相信它现在是 Windows SDK 的一部分(曾经是 Platform SDK).
Not sure how you want to automate this, through script, code, etc. But in any case, this functionality is all available through the Windows Installer SDK, which I believe is part of the Windows SDK now (used to be the Platform SDK).
无论如何,这是我过去用来手动将文件添加到 MSI 的 VBScript.已经有一段时间了,但我只是在 MSI 上运行它进行测试,并使用 Orca 进行验证,然后将程序集添加到二进制表中.这应该会为您指明正确的方向.
Regardless, here is a VBScript I have used in the past to manually add a file to an MSI. It has been a while, but I just ran it on a MSI to test, and verified with Orca and the assembly was added to the binary table. This should point you in the right direction.
Option Explicit Const msiOpenDatabaseModeTransact = 1 Const msiViewModifyAssign = 3 Dim installer : Set installer = Nothing Set installer = Wscript.CreateObject("WindowsInstaller.Installer") Dim sqlQuery : sqlQuery = "SELECT `Name`,`Data` FROM Binary" Dim database : Set database = installer.OpenDatabase("YourInstallerFile.msi", 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, "InstallUtilLib.dll" view.Modify msiViewModifyAssign, record database.Commit Set view = Nothing Set database = Nothing希望这有帮助!
更多推荐
如何修改内容/替换 .msi 文件的二进制文件作为构建后步骤?
发布评论