Uninstall Package - PowerShell
Overview
Uninstall-Package removes installed NuGet packages from the current project. It is primarily used to manage project dependencies, remove unused packages, or troubleshoot package-related issues.
Syntax
Uninstall-Package [-Name] <PackageNames> [[-Version] <Version>] [[-ProjectName] <ProjectNames>] [[-Force] [<-IncludePreview>] [-ResolveDependencies]] [[-SkipDependencies] [-WhatIf]] [[-NoCache]] [<-Throw>] [[-Lastest] [-OutputVerbose] [-ErrorAction <Action>]
Options/Flags
- -Name: Specifies the name(s) of the package(s) to uninstall.
 - -ProjectName: Specifies the project(s) from which to uninstall the package(s). Defaults to the current project.
 - -Version: Specifies the version of the package to uninstall.
 - -Force: Forces uninstallation of the package, even if it has dependent packages.
 - -IncludePreview: Includes preview versions of the package in the search.
 - -ResolveDependencies: Resolves package dependencies during uninstallation.
 - -SkipDependencies: Skips resolving package dependencies during uninstallation.
 - -WhatIf: Shows what would happen without actually uninstalling the package(s).
 - -NoCache: Prevents using the NuGet package cache.
 - -Throw: Throws an error if the package cannot be uninstalled.
 - -Latest: Uninstalls the latest version of the package.
 - -OutputVerbose: Displays detailed output during uninstallation.
 - -ErrorAction: Specifies the action to take when an error occurs.
 
Examples
Uninstall a specific package:
Uninstall-Package MyPackage
Uninstall a specific version of a package:
Uninstall-Package MyPackage -Version 1.2.3
Uninstall a package from multiple projects:
Uninstall-Package MyPackage -ProjectName Project1,Project2
Force uninstallation of a package with dependent packages:
Uninstall-Package MyPackage -Force
Common Issues
- Missing dependencies: Ensure that all dependent packages are also uninstalled or resolved using 
-ResolveDependencies. - Package not found: Verify the package name and version are correct.
 - Access denied: Check permissions for the project directory and NuGet repositories.
 
Integration
Uninstall-Package can be integrated with other PowerShell commands for advanced package management tasks:
- Get-Package: Lists installed packages.
 - Install-Package: Installs NuGet packages.
 - Update-Package: Updates installed packages.