【问题标题】:Chocolately `Get-ExecutionPolicy` - Uncaught ReferenceError: Get is not definedChocolatey `Get-ExecutionPolicy` - 未捕获的 ReferenceError:未定义获取
【发布时间】:2023-03-05 06:53:01
【问题描述】:

我正在遵循Chocolately Install 步骤(Windows 7),但遇到了一些问题。

首先,我打开了命令提示符(使用以管理员身份运行打开它),但是在尝试执行Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))时,我得到了这个错误:

Uncaught SyntaxError: Unexpected identifier

..我的命令的 https: 部分突出显示。

此外,当我尝试执行Get-ExecutionPolicy 时,会导致:

Uncaught ReferenceError: Get is not defined

有什么想法可能是错的吗?

* 更新 *

当我在 PowerShell 中尝试相同的命令时,我收到此错误:

PS C:\Users\mylogin> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtoc ol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;即 ((新对象 System.Net.WebClient).DownloadString ('https://chocolatey.org/install.ps1')) 异常设置 “SecurityProtocol”:“无法将值“3312”转换为类型 “System.Net.SecurityProtocolType”由于无效的枚举值。 指定以下枚举值之一,然后重试。这 可能的枚举值为“Ssl3,Tls”。”在 line:1 char:85 + Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]:: https://ch ocolatey.org/install.ps1')) + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException

使用“1”个参数调用“DownloadString”的异常:“The 底层连接已关闭:出现意外错误 发送。”在 line:1 char:219 + Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.Se rvicePointManager]::SecurityProtocol -bor 3072; iex ((新对象 System.Net.WebClient).DownloadString https://ch ocolatey.org/install.ps1')) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

【问题讨论】:

  • 您是在 PowerShell 中执行这些命令吗?是 PowerShell v2($PSVersionTable 会告诉你)吗?
  • 我正在使用命令提示符执行它们。我再次尝试使用 PowerShell,并用它给出的不同错误更新了我的答案。 (是的,我的 PSVersion 是 2.0 。)
  • 他们为什么选择让安装变得如此难以置信复杂?自 90 年代以来我一直在使用 Microsoft Windows,我从未见过如此复杂的安装过程。为什么不简单地让用户下载一个简单的 EXE 文件,或者一个带有 EXE 和 helpers 的 ZIP 文件,或者一个简单的“Next,Next,Next,Finish”设置 EXE?
  • 那么...你解决了这个问题吗兄弟?解决方案是什么?

标签: shell command-line chocolatey


【解决方案1】:
  1. Chocolatey.org下载chocolatey最新版本

  2. 将文件扩展名重命名为 .zip

  3. 解压文件

  4. 打开 PowerShell

  5. 打开提升的 PowerShell 调用:

    Start-Process powershell -Verb runAs
    
  6. 转到解压 Chocolatey 所在位置的工具文件夹

  7. 致电:& .\chocolateyInstall.ps1 以允许 Chocolatey 安装

  8. 将 choco 位置的路径添加到 system 环境 PATH:

    C:\ProgramData\chocolatey\bin
    
  9. 重新启动您的控制台和 VS Code(如果您使用的话)

【讨论】:

  • 非常感谢!这在 32 位 Windows 7 上运行就像一个魅力!
  • 要提取nupkg,只需将chocolatey.0.10.15.nupkg 重命名为chocolatey.0.10.15.zip并使用windows默认提取器
【解决方案2】:

Chocolatey.org requires TLS 1.2 能够连接。此错误表明您不支持已安装:

System.Net.WebClient).DownloadString ('https://chocolatey.org/install.ps1')) Exception setting "SecurityProtocol": "Cannot convert value "3312" to type "System.Net.SecurityProtocolType" due to inv alid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Ssl3, Tls"

我之前链接到的博客文章中的部分应该会有所帮助:

如果您发现自己正在配置计算机,例如 Windows 7、Windows Server 2008 或更早版本,您会发现在我们实施此更改后,这些计算机将无法与 Chocolatey 社区存储库通信。对于这些情况,您需要为 Chocolatey 使用 alternative installation methods。我们强烈建议使用offline Chocolatey installation,因为它提供了最大的灵活性和可靠性。

Chocolatey install page 上列出了要求:

  • Windows 7+ / Windows Server 2003+
  • PowerShell v2+(由于TLS 1.2 requirement,从本网站安装的最低版本为 v3)
  • .NET Framework 4+(如果您没有安装 .NET 4.0,安装将尝试安装)(由于TLS 1.2 requirement,从本网站安装的最低版本为 4.5)

我的建议是全面修补您的 Windows 7 系统,安装 .NET 4.5,然后尝试。请记住,自今年 1 月以来,Windows 7 已停止支持。

【讨论】:

  • 谢谢。我已经按照chocolatey.org/docs/installation#completely-offline-install 的两个步骤进行操作,所以我现在下载了chocolatey.0.10.15.nupkg。我如何从这里安装它? (我找到了 chocolatey.org/docs/how-to-setup-offline-installation ,但很混乱。)
  • 您需要按照脚本文件中的代码(chocolatey.org/install.ps1 - 需要 TLS1.2 才能查看)进行安装。它从内存中提取包并运行 ChocolateyInstall.ps1 文件 - 但请检查一下,因为我已经有一段时间没有查看它了。
  • 我正在使用 Windows 7 的替代安装并获得相同的错误异常设置“SecurityProtocol”:由于枚举值无效,“无法将值“3072”转换为类型“System.Net.SecurityProtocolType”。指定以下枚举值之一,然后重试。可能的枚举值是“Ssl3,Tls”。”
  • Windows 7 不包含 TLS 1.2 的密码,因此尝试设置它是行不通的。你需要做一个完整的offline install of Chocolatey。请注意,即使在安装之后,您也无法使用 Chocolatey.org 下载包,因为它需要 TLS 1.2,因此您需要使用内部包存储库。
猜你喜欢
  • 2020-01-25
  • 1970-01-01
  • 2023-01-23
  • 2016-11-03
  • 2011-01-05
  • 2016-01-02
  • 2013-10-06
  • 2016-12-17
相关资源
最近更新 更多