Reputation: 127
PowerShell 5 and 7 are different still when it comes to PackageManagers.
Chocolatey seems not to be 'integrated' yet and I cannot use Chocolatey in PowerShell 7 as I do in PowerShell 5.
I have installed chocolatey the way their site says but this lets me use chocolatey with starting my command with choco.
How can I configure Chocolatey in PowerShell 7 so that I can use it like I do in PowerShell 5.
Find-Package -ProviderName Chocolatey -Name <packagename>
Upvotes: 4
Views: 3756
Reputation: 51
I manage the Chocolatier community project that mklement0 mentions in their (excellent) answer.
You're correct that PackageManagement works a bit differently under PowerShell 7, and on its initial release, many PackageManagement providers didn't work at all. The defect in PowerShell 7 was fixed in their 7.0.1 release, though there is still some work for PackageManagement provider maintainers to integrate with PowerShell 7.
As of May 2020, the Chocolatier provider will work with both PowerShell 5.1 and PowerShell 7, even though Chocolatey is written in the older .NET Framework that isn't compatible with PowerShell 7. When the provider runs under PowerShell 7, it will construct and run the Chocolatey CLI commands for you (ex: choco install firefox
), bypassing the .NET compatibility problem.
If you're still interested in using PackageManagement to interact with Chocolatey, I'd recommend giving Chocolatier a try. I've iterated on it through both personal and professional use (works with private repositories and Desired State Configuration), and though I'm a bit biased, am pretty happy with it.
Upvotes: 5
Reputation: 437933
As of PowerShell [Core] 7, it looks like you cannot use 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
.
However, direct use of Chocolatey via its CLI, choco.exe
, works just fine in PowerShell [Core] (an *.exe
file runs as long as its runtime is present on the system, which needn't be the same runtime as PowerShell's).
Read on for background information:
It looks like implementing a PackageManagement provider would require access to Chocolatey APIs in a manner that supports only .NET Framework (FullCLR), not also .NET Core (on which PowerShell [Core] is built)[1]; a quote from the read-me of Chocolatier, a community-provided alternative to the never-released prototype of the official provider:
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.
As for use on Windows PowerShell:
The official - Windows PowerShell-only - prototype for the Chocolatey PackageManagement provider has to date, many years later, not been implemented; here's what the docs say, retrieved on 13 Apr 2020 (emphasis added):
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.
Note:
The aforementioned Chocolatier, which builds on ChocolateyGet, seems to be the more actively maintained project as of this writing.
There is a fairly recent pending 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] If you know details, do let us know.
Upvotes: 7