Powershell 中的错误 运行wix ExeCommand:无法识别术语“::SecurityProtocol”

Error running wix ExeCommand in Powershell: The Term "::SecurityProtocol" is not recognized

我正在尝试 运行 一个 Powershell 命令来下载和 运行 一个 exe。为了与 win 8.1 兼容,我研究过我必须使用 ssl 1.2 () 尽管 运行 宁此命令:

[Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

出现错误:术语 ::SecurityProtocol 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。

我 运行ning 的整个命令如下所示:

powershell.exe [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 ;
Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; 
& $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install

有人知道为什么会出现这个错误吗?或者有更简单的方法来 运行 这个吗? 我做了很多研究,但找不到任何有用的东西。

编辑 1: 运行直接在 powershell 中执行命令后(开头没有 powershell.exe)它工作正常(也将“&”;替换为“&”),尽管 运行通过 msi 命令执行安装程序它没有。 我在 Product.wxs 中的自定义操作:

    <CustomAction Id='DownloadAndInvokeBootstrapper' Directory="TARGETDIR" Execute="deferred" ExeCommand='powershell.exe [Net.ServicePointManager]::SecurityProtocol =  [System.Net.SecurityProtocolType]::Tls12;
                                                                                                          Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ;
                                                                                                          &amp; $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install' Return='check'/>

编辑 2

似乎是通过构建项目,它至少错过了导致特定错误消息的方括号中的语句。 有没有人知道另一种写那句话的方法,或者我必须把东西 before/after 放在方括号中?

我找到了解决办法,你必须把 execommand 放在它自己的 属性 中,然后你必须执行 属性。这样 [] 就不会被删除:

 <Property Id='EXECOMMAND' Value='powershell.exe -windowstyle hidden [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 ; Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; &amp; $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install'/>
 <CustomAction Id='DownloadAndInvokeBootstrapper' Directory="TARGETDIR" Execute="deferred" ExeCommand='[EXECOMMAND]' Return='check'/>