19

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.

mike
  • 1,202
  • 1
  • 7
  • 20
  • 1
    Couldn't you just take a text editor like Notepad++ and do a search and replace? – germi Dec 12 '19 at 13:50
  • 1
    what sort of quantity of projects are we talking? and are they new-style or old-style csproj? yes, you'll need to change each project, but you can do this just by editing the csproj; and *if you plan ahead*, in new-style (.net core style) csproj files, you can do it all via a single place, usually `Directory.build.props`, by declaring `` or `` *there* – Marc Gravell Dec 12 '19 at 13:57

5 Answers5

13

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.

Fire Lancer
  • 29,364
  • 31
  • 116
  • 182
  • Don't we need to update all assemblies version is in `...` and `...` as per target version and dlls version? – Sukhjeevan Mar 07 '21 at 04:48
  • I tested changing .Net from 4.0 to 4.8 using VS2019. It added a `Prefer32Bit` property and modified `Project ToolsVersion` in the .csproj file, and also modified my app.config file. – Mr. Boy Feb 09 '22 at 10:53
9

Relplace all occurances of

<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>

with

<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>

in the all *.csproj files. You can use Notepad++ for it.

Igor Buchelnikov
  • 505
  • 4
  • 14
  • When I changed framework in VS2019, it made several other changes in .csproj and app.config files. Not sure if they are important. – Mr. Boy Feb 09 '22 at 10:52
3

So i gone through the PR's on Git, so you are not alone. Someone has already posted a release package which works for .NET 4.8 with VS2019

Here is the OPEN PRs, which is waiting to be merged

4.7

4.8 and VS 2019

release for VS2019 which actually works, according to the commit and comments. Give it a try

HariHaran
  • 3,642
  • 2
  • 16
  • 33
2

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

Vasil Popov
  • 1,210
  • 14
  • 22
0

A few years later, if it can help some developers, as Target Framework Migrator does not work on VS2022, there is now a Microsoft .NET Upgrade Assistant that you can find on the VisualStudio Marketplace: https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.upgradeassistant&ssr=false#review-details

Unfortunately, it does not allow to migrate from old .NET FW to new .NET FW 4.8 or 4.8.1, but only to: .NET 6.0 or 7.0 or 8.0, .NETSTandard 2.0 or 2.1

More info on Microsoft blog: https://devblogs.microsoft.com/dotnet/upgrade-assistant-now-in-visual-studio/

Where the upgrade tool is after vsix install (right click on project): enter image description here

Xavave
  • 645
  • 11
  • 15