使用参数从 Wix 调用 PowerShell 脚本
Calling a PowerShell script from Wix with Parameters
我正在努力解决这个问题,因为 Wix CustomAction 使用一组参数(包括 PowerShell 脚本)调用 PowerShell.exe,但随后我需要将其他参数传递给 powershell 脚本。我试图简化,在不同的地方尝试了各种引号以尝试在逻辑上分隔参数,但我没有运气。这是我拥有的:
<SetProperty Id="ReplaceConnectionString"
Before ="ReplaceConnectionString"
Sequence="execute"
Value=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File "[INSTALLFOLDER]ReplaceConnectionString.ps1" "MyParam"" />
<CustomAction Id="ReplaceConnectionString" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="check" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="ReplaceConnectionString" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
我做错了什么?
我找到的解决方案是按照 Mathias 的建议,即使用参数名称。
另一个问题是 PowerShell 不喜欢参数上的尾随 /,通过向参数添加额外的 / 解决了这个问题。这是我的结论:
<SetProperty Id="ReplaceConnectionString"
Before ="ReplaceConnectionString"
Sequence="execute"
Value=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File "[INSTALLFOLDER]ReplaceConnectionString.ps1" -servername "[DB_SERVER]" -database "[DB_DATABASE]" -configPath "[INSTALLFOLDER]\"" />
我正在努力解决这个问题,因为 Wix CustomAction 使用一组参数(包括 PowerShell 脚本)调用 PowerShell.exe,但随后我需要将其他参数传递给 powershell 脚本。我试图简化,在不同的地方尝试了各种引号以尝试在逻辑上分隔参数,但我没有运气。这是我拥有的:
<SetProperty Id="ReplaceConnectionString"
Before ="ReplaceConnectionString"
Sequence="execute"
Value=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File "[INSTALLFOLDER]ReplaceConnectionString.ps1" "MyParam"" />
<CustomAction Id="ReplaceConnectionString" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="check" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="ReplaceConnectionString" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
我做错了什么?
我找到的解决方案是按照 Mathias 的建议,即使用参数名称。
另一个问题是 PowerShell 不喜欢参数上的尾随 /,通过向参数添加额外的 / 解决了这个问题。这是我的结论:
<SetProperty Id="ReplaceConnectionString"
Before ="ReplaceConnectionString"
Sequence="execute"
Value=""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -ExecutionPolicy Bypass -InputFormat None -NoProfile -File "[INSTALLFOLDER]ReplaceConnectionString.ps1" -servername "[DB_SERVER]" -database "[DB_DATABASE]" -configPath "[INSTALLFOLDER]\"" />