PowerShell 7 使用 Chocolatey 作为 PackageManager

PowerShell 7 use Chocolatey as PackageManager

PowerShell 5 和 7 在 PackageManagers 方面仍然不同。
Chocolatey 似乎还没有 'integrated',我不能像在 PowerShell 5 中那样在 PowerShell 7 中使用 Chocolatey。

我已经按照他们网站上说的方式安装了 chocolatey,但这让我可以通过使用 choco 启动我的命令来使用 chocolatey。

如何在 PowerShell 7 中配置 Chocolatey,以便我可以像在 PowerShell 5 中一样使用它。
Find-Package -ProviderName Chocolatey -Name <packagename>

  • 从 PowerShell [Core] 7 开始,您似乎 不能 使用 Chocolatey as a provider for PowerShell's PackageManagement module, which means that you cannot discover or install Chocolatey packages with Find-Package and Install-Package.

  • 但是,直接 通过其 CLIchoco.exe 使用 Chocolatey 在 PowerShell 中工作得很好[Core]*.exe 文件只要其运行时存在于系统上就会运行,它不必与 PowerShell 的运行时相同)。

继续阅读以获取背景信息:


看起来实施 PackageManagement 提供程序需要以仅支持 .NET Framework (FullCLR) 的方式访问 Chocolatey API,而不是 .NET Core(PowerShell [Core] 构建于其上)[1];引自 Chocolatier 的自述文件,这是社区提供的替代官方提供者 从未发布的原型 的替代方法:

Currently, Chocolatier works on Full CLR. It is not supported on CoreClr (...). The primary reason is that the current version of choco.exe does not seem to support CoreClr yet.

至于在 Windows PowerShell 上的使用:

Chocolatey PackageManagement 提供程序的官方 - Windows 仅限 PowerShell - 原型至今仍未实施;这是 the docs 所说的,于 2020 年 4 月 13 日检索(强调):

Chocolatey has a prototype provider for the built-in package manager on Windows 10/Windows Server 2016 that was created by Microsoft awhile back. It is not fully functional and it may have security issues. If you want to use Chocolatey with PackageManagement, we recommend using ChocolateyGet, which is a nice bridge until an official one is implemented. No ETA has been defined.

注:

  • 前面提到的 Chocolatier,它建立在 ChocolateyGet 之上,在撰写本文时似乎是维护得更积极的项目。

  • 最近有一个未决 PR by a community member for the official prototype, but it hasn't received any attention; also, it isn't complete yet either; for the full backstory, see this GitHub issue


[1]如果您知道详情,请告诉我们。

我管理 mklement0 在他们的(优秀)回答中提到的 Chocolatier 社区项目。

您说得对,PackageManagement 在 PowerShell 7 下的工作方式略有不同,并且在其初始版本中,许多 PackageManagement 提供程序根本无法工作。 PowerShell 7 中的 defect 已在其 7.0.1 版本中修复,但 PackageManagement 提供程序维护者仍需要做一些工作才能与 PowerShell 7 集成。

自 2020 年 5 月起,Chocolatier 提供程序将与 PowerShell 5.1 和 PowerShell 7 一起使用,即使 Chocolatey 是在与 PowerShell 7 不兼容的旧 .NET Framework 中编写的。当提供程序 运行s 在 PowerShell 7 下,它将为您构造和 运行 Chocolatey CLI 命令(例如:choco install firefox),绕过 .NET 兼容性问题。

如果您仍然对使用 PackageManagement 与 Chocolatey 交互感兴趣,我建议您尝试 Chocolatier。我通过个人和专业用途(使用私有存储库和 Desired State Configuration)对其进行了迭代,虽然我有点偏见,但我对此非常满意。