'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?
Solution 1:[1]
A simple example of how to remove NuGet provider
(Get-PackageProvider|where-object{$_.name -eq "nuget"}).ProviderPath|Remove-Item -force
Restart-Computer
Solution 2:[2]
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 deniederror, even with elevation.
- Deleting the DLL will only succeed if no session has it currently loaded; if that isn't ensured, you'll get an
In the elevated session (in which you must not have submitted any
PackageManagementcommands), 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 /
sudosession.Start a new (non-elevated) session for the change to take effect:
Get-PackageProvidershould then no longer list theNuGetprovider.
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mklement0 |
| Solution 2 | |
| Solution 3 | Bakudan |
