是否可以使用 Wix 在安装程序中嵌入 PowerShell 脚本并从那里 运行 而不是位置?
Is it possible to embed a PowerShell script inside the installer and run it from there instead of a location, using Wix?
我想使安装程序 运行 成为 PowerShell 脚本,然后再安装所有其他文件。但是,目前它是如何构建的,它只适用于 运行 安装完成后的脚本,因为它将 powershell 脚本放在目标目录中。现在,这可能可以通过使目录始终存在来解决。但是,我不想一直在安装程序中提供脚本,我希望将脚本嵌入到安装程序中,并从那里 运行 或者至少 运行 命令是在脚本文件中。
我尝试将自定义操作的 "After" 更改为 "InstallInitialize",但它会抛出一个错误,指出它无法指定路径(这是合乎逻辑的,因为路径尚未创建,因为脚本在安装文件之前执行)。
这里是一些代码,其中提供了 运行 宁 powershell 脚本的所有逻辑:
<DirectoryRef Id="INSTALLFOLDER">
<Component Id ="SOMESCRIPT" Guid="">
<File Id="SOMESCRIPT" Name="My-Script.ps1" Source="My-Script.ps1" />
</Component>
</DirectoryRef>
<Property Id="POWERSHELLEXE">
<RegistrySearch Id="POWERSHELLEXE"
Type="raw"
Root="HKLM"
Key="SOFTWARE\Microsoft\PowerShell\ShellIds\Microsoft.PowerShell"
Name="Path" />
</Property>
<Condition Message="This application requires Windows PowerShell.">
<![CDATA[Installed OR POWERSHELLEXE]]>
</Condition>
<SetProperty Id="PSscript"
After="PSscript"
Sequence="execute"
Value =""[POWERSHELLEXE]" -Version 3.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& '[#SOMESCRIPT]' ; exit $$($Error.Count)"" />
<CustomAction Id="PSscript"
BinaryKey="WixCA"
DllEntry="WixQuietExec"
Execute="deferred"
Return="check"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="PSscript" After="InstallInitialize"><![CDATA[NOT Installed]]></Custom>
</InstallExecuteSequence>
预期结果是脚本被嵌入到 .msi 文件中,而不依赖于仅在安装后创建的文件。错误消息是它找不到脚本,因为它尚未安装。我实际上不想将脚本文件放在开始的文件夹中,我只想将脚本 运行 放在安装程序中,而不对脚本文件执行任何其他操作。
This the only PS extension 的 Wix 我可以在网上找到,但似乎这也可能仅限于您的情况。
为了在安装 运行 脚本之前支持它们,我们(在 Advanced Installer)创建了预定义支持,以便在安装启动并执行时将 PS 脚本提取为临时文件它来自那个临时位置。如果 Wix 有类似的支持,我不会。
披露:我在团队建设 Advanced Installer 工作。
我想使安装程序 运行 成为 PowerShell 脚本,然后再安装所有其他文件。但是,目前它是如何构建的,它只适用于 运行 安装完成后的脚本,因为它将 powershell 脚本放在目标目录中。现在,这可能可以通过使目录始终存在来解决。但是,我不想一直在安装程序中提供脚本,我希望将脚本嵌入到安装程序中,并从那里 运行 或者至少 运行 命令是在脚本文件中。
我尝试将自定义操作的 "After" 更改为 "InstallInitialize",但它会抛出一个错误,指出它无法指定路径(这是合乎逻辑的,因为路径尚未创建,因为脚本在安装文件之前执行)。
这里是一些代码,其中提供了 运行 宁 powershell 脚本的所有逻辑:
<DirectoryRef Id="INSTALLFOLDER">
<Component Id ="SOMESCRIPT" Guid="">
<File Id="SOMESCRIPT" Name="My-Script.ps1" Source="My-Script.ps1" />
</Component>
</DirectoryRef>
<Property Id="POWERSHELLEXE">
<RegistrySearch Id="POWERSHELLEXE"
Type="raw"
Root="HKLM"
Key="SOFTWARE\Microsoft\PowerShell\ShellIds\Microsoft.PowerShell"
Name="Path" />
</Property>
<Condition Message="This application requires Windows PowerShell.">
<![CDATA[Installed OR POWERSHELLEXE]]>
</Condition>
<SetProperty Id="PSscript"
After="PSscript"
Sequence="execute"
Value =""[POWERSHELLEXE]" -Version 3.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& '[#SOMESCRIPT]' ; exit $$($Error.Count)"" />
<CustomAction Id="PSscript"
BinaryKey="WixCA"
DllEntry="WixQuietExec"
Execute="deferred"
Return="check"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="PSscript" After="InstallInitialize"><![CDATA[NOT Installed]]></Custom>
</InstallExecuteSequence>
预期结果是脚本被嵌入到 .msi 文件中,而不依赖于仅在安装后创建的文件。错误消息是它找不到脚本,因为它尚未安装。我实际上不想将脚本文件放在开始的文件夹中,我只想将脚本 运行 放在安装程序中,而不对脚本文件执行任何其他操作。
This the only PS extension 的 Wix 我可以在网上找到,但似乎这也可能仅限于您的情况。
为了在安装 运行 脚本之前支持它们,我们(在 Advanced Installer)创建了预定义支持,以便在安装启动并执行时将 PS 脚本提取为临时文件它来自那个临时位置。如果 Wix 有类似的支持,我不会。
披露:我在团队建设 Advanced Installer 工作。