Targeting latest .NET framework with MVC sites

   —   

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

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! =)

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

Your Guide to Transitioning to MVC with Kentico 12

Share this article on   LinkedIn