在安装Wix安装程序之前运行PowerShell脚本。

huangapple go评论71阅读模式
英文:

Run powershell script in wix installer before install

问题

我想在Wix安装项目的安装阶段之前运行一个PowerShell脚本。

我可以成功地在安装之后运行脚本,因为脚本已经存在。我想将脚本嵌入到.msi文件中,并在安装之前引用它。

这需要从.msi文件中引用脚本,或者从临时副本中引用脚本。我无法找到一种在安装阶段之前引用数据库中的文件的方法。

从日志文件中可以看到,安装程序使用一个值引用了“C:\Users\username\AppData\Local\Temp\nnnnneff.msi”的“DATABASE”属性。我认为这是安装程序创建安装数据库的位置。文件应该在那里,或许我可以以某种方式引用它。

    <CustomAction Id="CA_RunPreinstallScript"
                  BinaryKey="WixCA"
                  DllEntry="WixQuietExec"
                  Execute="immediate"
                  Return="check"
                  Impersonate="no" />

    <SetProperty Id="CA_RunPreinstallScript"
                 Before="CA_RunPreinstallScript"
                 Sequence="execute"
                 Value=""[POWERSHELLEXE]" -NoLogo -NonInteractive -InputFormat None -ExecutionPolicy Bypass -NoProfile -File "$(var.ProjectDir)\Resources\PreInstall.ps1"" />

    <InstallExecuteSequence>
     <Custom Action='CA_RunPreinstallScript' After='InstallInitialize'></Custom>
    </InstallExecuteSequence>

这个示例不起作用。-File参数指向了我系统上的一个固定位置,而不是引用安装程序文件中的脚本。

有没有办法引用数据库中缓冲的文件,并将其作为PowerShell自定义操作中的-File值使用?

(有很多问题涉及到这个问题,但我没有在任何地方找到真正的答案。)

英文:

I would like to run a powershell script before the install phase in a wix install project.

I can successfully run a script after the install, because the script is already there. I would like to embed the script in the .msi file, and reference it during the installation, but before it is installed.

This would require referencing the script from within the .msi file, or from a temporary copy. I can't figure out a way to reference files in the database before they are installed during the install phase.

From looking at the log file, I can see that the installer sets a 'DATABASE' property with a value that references "C:\Users\username\AppData\Local\Temp\nnnnneff.msi". I'm thinking this is where the installer is creating the database for the install. It would seem that the file would be there, and that perhaps I could reference it somehow.

    <CustomAction Id="CA_RunPreinstallScript"
                  BinaryKey="WixCA"
                  DllEntry="WixQuietExec"
                  Execute="immediate"
                  Return="check"
                  Impersonate="no" />

    <SetProperty Id="CA_RunPreinstallScript"
                 Before="CA_RunPreinstallScript"
                 Sequence="execute"
                 Value=""[POWERSHELLEXE]" -NoLogo -NonInteractive -InputFormat None -ExecutionPolicy Bypass -NoProfile -File "$(var.ProjectDir)\Resources\PreInstall.ps1"" />

    <InstallExecuteSequence>
     <Custom Action='CA_RunPreinstallScript' After='InstallInitialize'></Custom>
    </InstallExecuteSequence>

This example doesn't work. The -File parameter is pointed to a hard location on my system, instead of referencing a script within the installer file.

Is there some way to reference a file buffered in the database and use it as the -File value in a powershell custom action?

(There are a number of questions that address this, but I didn't find a real answer anywhere.)

答案1

得分: 0

我最终在我的解决方案中创建了一个C# Wix自定义操作项目,并创建了自定义操作。这种类型的自定义操作可以在安装序列的任何位置调用,甚至可以在用户界面序列之前调用。

根据自定义操作插入的位置,对于可用的“会话”数据有一些限制,但它提供了一种与安装过程进行交互的强大方式。

我可以在安装开始之前插入一个用C#创建的自定义操作,并检测旧版安装,并根据起始条件调整新的安装。我还可以在安装后运行操作,以处理安装程序完成修改系统后的细节。

英文:

I ended up creating a C# Wix Custom Action project in my solution and created custom actions. This type of custom action can be called anywhere in the install sequence, even before the User Interface sequence.

There are limitations on what 'session' data is available depending upon where the custom actions are inserted, but it creates a powerful way to interact with the install process.

I can insert a Custom Action created in C# before the installation starts, and detect legacy installations, and tailor the new installation based on the starting conditions. I can also run actions later in the install to handle details after the installer finishes modifying the system.

huangapple
  • 本文由 发表于 2023年8月8日 21:53:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76860226.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定