Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upgrade all solution projects .Net framework 4.5.1 to 4.8 Visual Studio 2019

I have a solution in Visual Studio 2019 with many C # projects. I need to retarget all of the projects from the .NET Framework 4.5.1 to 4.8. Is it possible to change target at once or do I have to do it separately with every single one of them?

PS: I tried 'TargetFrameworkMigrator', but it doesn't work with (VS2019) / .net 4.8.

Thank you for your help.

like image 645
mike Avatar asked Dec 12 '19 13:12

mike


People also ask

How can I change my net Framework version in VS 2019?

Right-click on your project. Select Properties. Select the Application tab. Change the Target Framework to the desired framework.

How do I upgrade my .NET Framework?

NET Framework version. To update the target framework for all projects, right-click on the project (one by one), click properties, and from the “Application” tab change the target framework to the desired one as in the following screenshot and select “Yes” in the popup that is displayed after the framework is changed.


2 Answers

VS unfortunately doesn't provide an easy way for .NET framework, and every project file has it's own setting. So the easiest way is probably a "Edit -> Find and Replace- > Replace in Files" on the directory in VS or any text editor you like.

For Framework projects, in every .csproj you want <TargetFrameworkVersion>v4.8</TargetFrameworkVersion> (from <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>), if you have any packages.config, there is targetFramework="net48" (from targetFramework="net451"). You will need to reload the solution after changing for VS to see them.

like image 102
Fire Lancer Avatar answered Sep 28 '22 03:09

Fire Lancer


Target Framework Migrator is now available for the Visual Studio 2019 and .Net 4.8. Unfortunately does not work for Core or .Net 5 / 6 ...

Keep in mind that tpdating the XML node <TargetFrameworkVersion> value with a text editor sounds fair solution, consider that the old format of the .csproj file also stores the target framework versions of the nuget dependencies and these should be updated to reduce possibilities of unexpected runtime errors.

After updating the projects target framework, you should reinstall all nuget packages. VS will tell this, but you can check this as well: How to reinstall NuGet packages

like image 45
Vasil Popov Avatar answered Sep 28 '22 04:09

Vasil Popov