Vimes
Vimes

Reputation: 11927

PowerShell PackageManagement, how to uninstall a package provider?

To troubleshoot a problem, I thought I'd try reinstalling the Chocolatey package provider. There appears to be no cmdlet to remove or uninstall a package provider. I'm not referring to removing a package source or package. I'm using PowerShell 5 on Windows 10.

Is there a way to uninstall a package provider?

Upvotes: 28

Views: 25240

Answers (4)

mklement0
mklement0

Reputation: 438388

To complement Harald F's helpful answer, given that the PackageManagement module as of version 1.4.7 still has no Uninstall-PackageProvider command (see all commands that come with the module with Get-Command -Module PackageManagement):

Note: To be able to undo this change later, make a note of the path reported by (Get-PackageProvider NuGet).ProviderPath and make a backup copy of that file.

Step-by-step instructions for removing the NuGet package provider, for example:

  • On Windows:

    • Copy the path of the NuGet package-provider assembly (DLL) to the clipboard:

      • (Get-PackageProvider NuGet).ProviderPath | Set-Clipboard
    • Start an elevated PowerShell session (run as admin - requires administrator credentials). To do that from an existing (non-elevated) session, run:

      • Start-Process -Verb RunAs (Get-Process -Id $PID).Path
    • Before continuing, close all other PowerShell sessions, which may include needing to exit Visual Studio Code.

      • Deleting the DLL will only succeed if no session has it currently loaded; if that isn't ensured, you'll get an Access denied error, even with elevation.
    • In the elevated session (in which you must not have submitted any PackageManagement commands), submit the following command to delete the NuGet package-provider assembly (DLL):

      • Remove-Item -Force <paste-the-previously-copied-path-here>
  • On macOS and Linux:

    • Start a PowerShell session with sudo. To do that from an existing (non-elevated) session, run:

      • sudo pwsh
    • Submit the following command to delete the NuGet package-provider assembly (DLL):

      • (Get-PackageProvider NuGet).ProviderPath | Remove-Item -Force
  • The remaining steps apply to all platforms:

    • Exit the elevated / sudo session.

    • Start a new (non-elevated) session for the change to take effect: Get-PackageProvider should then no longer list the NuGet provider.

Upvotes: 4

Emil Gitman
Emil Gitman

Reputation: 69

A simple example of how to remove NuGet provider

(Get-PackageProvider|where-object{$_.name -eq "nuget"}).ProviderPath|Remove-Item -force
Restart-Computer

Upvotes: 2

Christophe Maggi
Christophe Maggi

Reputation: 132

If I understand what you want :

Uninstall-Package [-Id] [-RemoveDependencies] [-ProjectName ] [-Force] [-Version ] [-WhatIf]

Use the -Force option to forces a package to be uninstalled.

Upvotes: -1

Harald F.
Harald F.

Reputation: 4773

Package providers are bundled with the WMF installation.

You can easily add package providers (and remove) if you know the search locations (even your own custom package providers).

Find where your package-provider is installed:

$p = (Get-packageProvider -name Chocolatey);
$p.ProviderPath

If you remove / move the assembly to somewhere outside the providers default search path; it will be unavailable (NB: Restart your host too see the effects).

Similarly can you add package providers by copying a exe / dll that implements the specifications for a packageprovider to the search location.

More documentation can be found here (implementing your own and the default search locations):

https://github.com/OneGet/oneget/wiki/Provider-assembly-search-locations https://github.com/OneGet/oneget/wiki/ImplementingPackageProvider

Upvotes: 27

Related Questions