Updating .NET Framework

For Kentico 12 MVC project to the latest version (4.7.2)

Update 1

Kentico engeneers found more robust solution (especially if you can't update LinqToTwitter nuget package for some reason). Please scroll to the bottom of the page for it.

Update 2

Microsoft VisualStudio 2019 doesn't have this problem with reinstalling Nuget packages after retargeting the Framework. This is a good reason to switch to the lates VS version! =)

Background

When I have an opportunity to start a new project with Kentico I always try to align everything possible to the latest version. Latest version of CMS, latest hotfix, latest supported .NET Framework version as well. Kentico 12 Release Notes document says:

The installer no longer provides the option to create Kentico projects targeting .NET Framework 4.7. Installed projects now always target the minimum supported .NET Framework version (4.6.1). If you wish to target a higher version, you can set it manually for your project in Visual Studio.

But it's not that straightforward as it seems. If you just retarget the .NET Framework version to 4.7.2 your Kentico 12 MVC solution will remain compilable. But following the best practices, after doing so you should reinstall all your Nuget packages like this:

Update-Package -reinstall -project DancingGoat

And you'll get the following error:

Update-Package : Unable to find package 'Rx-Core'. Existing packages must be restored before performing an install or update.
At line:1 char:1
+ Update-Package -reinstall -project DancingGoat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Update-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand
 

Solution

So let's fix it. The right way. The main reason for this error is LinqToTwitter nuget package version 4.0.0 which has Rx-Main, Rx-PlatformServices, Rx-Linq, Rx-Core, Rx-Interfaces packages in dependencies which do not exist for .NET Framework 4.7.2 anymore.

  • First, update LinqToTwitter package
Update-Package LinqToTwitter -version 5.0.0 -project DancingGoat
  • Remove Rx-* packages
Uninstall-Package Rx-Main -project DancingGoat
Uninstall-Package Rx-PlatformServices -project DancingGoat
Uninstall-Package Rx-Linq -project DancingGoat
Uninstall-Package Rx-Core -project DancingGoat
Uninstall-Package Rx-Interfaces -project DancingGoat
  • Retarget project to .NET 4.7.2
  • Reinstall all Nuget packages
Update-Package -reinstall -project DancingGoat

After performing these steps your solution will compile again. Happy coding!

Update 1

Here is the solution from the Kentico QnA page:

  • retarget the framework to 4.7.2
  • run the following commands in the Package Manager Console:
Uninstall-Package -Id Rx-Main -Force -RemoveDependencies;
Uninstall-Package -Id linqtotwitter -Force;
Update-Package -reinstall;
Install-Package -Id linqtotwitter -Version 4.0.0