我想修改现有的MSI包,它会检查目标上是否至少安装了PowerShell 5.0版。如果不是,安装程序应该中止。
是否有一种简单的方法可以检测WIX项目中安装的PowerShell版本?
基于此link,我添加了以下自定义操作:
<Property Id="POWERSHELLEXE" Secure="yes">
<RegistrySearch Id="POWERSHELLEXE"
Type="raw"
Root="HKLM"
Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
Name="Path" />
</Property>
<Condition Message="This application requires Windows PowerShell.">
<![CDATA[Installed OR POWERSHELLEXE]]>
</Condition>
<SetProperty Id="TestPSVersion"
Before="TestPSVersion"
Sequence="execute"
Value =""[POWERSHELLEXE]" -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command { $PSVersionTable.PSVersion.Major -eq 7 }" />
<CustomAction Id="TestPSVersion"
BinaryKey="WixCA"
DllEntry="CAQuietExec"
Execute="deferred"
Return="check"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="TestPSVersion" Before="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
我实际上正在检查PS版本7以强制自定义操作失败。根据日志,可以看到在安装过程中调用自定义操作:
Action 08:42:09: SetTestPSVersion.
Action start 08:42:09: SetTestPSVersion.
Action ended 08:42:09: SetTestPSVersion. Return value 1.
Action 08:42:09: TestPSVersion.
Action start 08:42:09: TestPSVersion.
TestPSVersion:
Action ended 08:42:09: TestPSVersion. Return value 1.
实际上我卡住了返回PSVersion检查的结果。任何人都可以帮我吗?
THX