如何修改的内容/替换.msi文件的二进制作为生成后步骤?步骤、文件、内容、msi

2023-09-08 01:00:24 作者:鱼腥味

在与x64系统一个CustomAction建立一个Visual Studio 2010的安装项目,Visual Studio中包含错误的版本 InstallUtilLib.dll 的:它安装了32位垫片,这将对于编译为64位CustomActions无法正常工作(在我的情况的要求,因为这取决于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 例外。

据这个职位(64位托管自定义与Visual Studio操作)​​,解决的办法是在 Orca.exe的并更换二元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:\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)

注意的:右键单击Solution Explorer中的设置项目,然后选择属性,打开了错误的对话框(属性页)。你想在属性窗口(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).

推荐答案

要如何自动执行此,通过脚本不知道,code等,但在任何情况下,该功能都是可以通过 Windows安装程序SDK 的,我相信这是部分Windows SDK的现在(以前是平台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).

无论如何,这里是一个VBScript我已经在过去使用的文件手动添加到MSI。它已经有一段时间,但我只是跑了一个微星的测试,并与海怪核实并将组件添加到二进制表。这应该指向你在正确的方向。

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

希望这有助于!

Hope this helps!