Remove nuget packages from a project in Visual Studio and restore from packages.config

I was recently in a situation where I multiple projects in solution that needed the same nuget packages, but a lot of unnecessary packages had also been added.

Firstly I wanted to quickly remove all of the nuget packages in a single project which can be done by entering the following into the Package Manager Console.

Get-Package -ProjectName "My.Project.Name" | Uninstall-Package -ProjectName "My.Project.Name" -RemoveDependencies -Force

Next I added just the packages I needed to that one project. The next step was to quickly update all of the other projects to have the same packages.

For each project I ran the same command as above to remove all the packages, then copied the packages.config containing the correct package information into each project. It’s then possible to restore all of the packages from the packages.config using the following command.

Update-Package –reinstall -ProjectName "My.Project.Name"
Posted on by Joe in ASP.NET, C#, Visual Studio 2008

Add a Comment