Reinstall NuGet packages after upgrading a project

We all have had projects which have been running for quite sometime. However, when we open them after a few months, we find many upgrades that can be performed.

Well, this happened to me this week and I found that my project which has been running for almost 5 years now, started off with .Net Framework 4.5. At present, it was still targeted to .Net Framework 4.5.2. So I decided to upgrade the runtime version to .Net Framework 4.7.2. Although this is good then I started seeing some warnings.

Some NuGet packages were installed using a target framework different from the current target framework and may need to be reinstalled. Visit http://docs.nuget.org/docs/workflows/reinstalling-packages for more information. Packages affected:

To be honest, we programmers always tend to ignore the warnings and focus more on errors. However, this is not the one that one should ignore especially if this is a library that will have to be referenced somewhere.

How to fix this?

The easiest way to do this is by executing this command in Package Manager Console

Update-Package -Reinstall -ProjectName Project.Name.Here

In the above command, we can see a parameter -Reinstall. It instructs the NuGet Package Manager to remove the NuGet packages and reinstall the same versions. This gives NuGet a chance to determine which assembly is most appropriate for the current framework targeted by the project.

To conclude, it was really easy to get rid of this warning as it can occur whenever a project is upgraded to a different target framework.

Happy Coding!

Latest posts by Anubhav Ranjan (see all)

Leave a Reply