Reinstall NuGet Packages without Updating
This article describes a quick way to reinstall all the packages in a .Net Framework solution or a single project.
When updating a project's target .Net Framework I am occasionally told in the output window I may need to reinstall a NuGet package or two. Inspection of the project's packages.config file typically shows something like:
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" requireReinstallation="true" />
This was for the System.Security.Cryptography.Algorithms package when I upgraded from .Net 4.6.1 to 4.7.2. The key bit to note is the requireReinstallation="true" attribute indicating a reinstall of this NuGet package is required.
This can be acheived through the GUI by manually removing and the installing the packages, but this is a little cumbersome if there are many packages to reinstall, or you have retargeted multiple projects.
Running the NuGet commang in Update-Package a Visual Studio Package Manager Console updates all packages, but the following command reinstalls all packages solution-wide:
Update-Package -reinstallThis can be ammended to reinstall packages for a single project using:
Update-Package -reinstall -Project ProjectName