Search code examples
powershellpackagepackage-managerschocolatey

PowerShell 7 use Chocolatey as PackageManager


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>


Solution

    • 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.