# c# – Nuget re-targeting after upgrading from .Net Framework 4.5 to 4.6.1

## The Question :

133 people think this question is useful

I have a .net solution with approx 30 projects, all of them targeting .Net Framework 4.5. and each referencing at least 3-4 NuGet packages.

We now need to update them to .Net Framework 4.6.1. So here’s what I need to know:

1. Do I need to re-target the NuGet packages as well or can I skip that since this will be an ‘in-place’ upgrade?
2. If yes, can I just update the packages.config file for each project by replacing targetFramework=”net45″ with targetFramework=”net461″ for each NuGet package? I’ve seen a few threads recommending uninstall and then reinstall the package via ‘update-package’ command. I tried that today but it I ended up with a few errors.
• Modifying the targetFramework in the packages.config file has no affect on the assemblies that are referenced in the project, assuming you are not using an .xproj, so doing that would not be the correct change. I would guess that not many NuGet packages have assemblies that explicitly target .NET 4.6 so I suspect that nothing would need to be retargeted. You should be able to review the lib directories of your NuGet packages to see what they target.
• So I ended up upgrading 75% of my NuGet packages to their latest versions. Post the upgrade the targetFramework attribute was automatically set to ‘net461’ for most of the packages. There are some packages which I will be upgrading later and they seem to work fine post the upgrade. Thanks.
• upgrading from 4.5.* to 4.* will work be design: msdn.microsoft.com/en-us/library/ff602939%28v=vs.110%29.aspx
• docs.microsoft.com/en-us/nuget/consume-packages/…

256 people think this answer is useful

The packages will not be retargeted automatically, but there is an automated fix for this.

In Package Manager Console simply run:

Update-Package -Reinstall



This will force the package manager to reinstall every package in every project (without changing the version of the referenced package).

By reinstalling the packages after the new framework is targeted this changes all the references to the correct version.

You may also run this against a single project with :

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



I have used this technique many times to fix nuget reference issues.

38 people think this answer is useful

1 Find all .csproj files and replace

<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>



with

<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>



2 Open Package Manager Console and run

Update-Package -Reinstall -IgnoreDependencies



3 Find all solutions then msbuild each one.