How to migrate .NET Framework 4.7.2 project to .NET Core 3.0 in Visual Studio 2019
Asked Answered
L

5

15

I have a Windows Forms application targeted for .NET Framework 4.7.2. As .NET Core 3.0 supports Windows Forms I'd like to try it. Is there any way to convert VS2019 project from .NET Framework to .NET Core or the only way possible is to create a new .NET Core project and add files from the old one?

I'm asking only about VS project migration, not any potential incompatibility issues.

Legault answered 23/9, 2019 at 18:12 Comment(7)
As shown in todays .NET Conf videos (see the live stream currently running on dotnetconf.net, rewind back to around 1:27-1:28 (1 hour + 27-28 minutes) into the video and watch), there is a new tool called "try-convert" that can attempt to make the conversion for you. How to install this tool, where to get it, I have no idea, it may be evident if you have Visual Studio 2019 and .NET Core 3 SDK installed though, which is why I leave this as a comment and not an answer.Mazur
learn.microsoft.com/en-us/dotnet/core/porting/winforms. Caveat, the winform designers don't support .NET Core yet, so you might also want to look into the latest VS 2019 Preview drop as well.Fontes
Olia Gavrysh (lady doing the presentation) said they will publish it tomorrow - 7 hours ago :) I will paste link as soon it is available.Hives
It could be interesting to test Winform migration .Net Core 3.0 for a future upgrade, but I wouldn't recommand it on a huge application that already have to run smoothly on production environment. Even for testing purpose, if you're not in haste, at least wait for a few weeks the official availability of required tools, it will be easier.Tallbott
@LasseVågsætherKarlsen I have Visual Studio 2019 with .NET Core 3 and there is no such file on disk. I think they even said as tool is not 100% successful it will not be part of official VS install.Hives
Any updates on the link to the migration tool?Advocation
@Advocation check my answer below, relased...Hives
H
12

[EDIT] Official tool released: try-convert

Check out releases for latest version.

Until official tool is published, here is link from some guy that has made alternative Migration-von-NET-Framework-zu-NET-Core-per-PowerShell

Hives answered 24/9, 2019 at 15:4 Comment(3)
The try-convert is not an official tool. They write: "This tool is not supported in any way" and "This is an open source project built by members of the .NET team in their spare time"Ventris
What is the command for upgrading framework from net20 to net47?Jest
getting error as "app.csproj contains a reference to System.Web, which is not supported on .NET Core. You may have significant work ahead of you to fully port this project" while applying command "try-convert -w app.csproj" what we do, is this possible force to migrate?Jest
S
1

Please follow this step:

Using Portability Analyzer

Use the following instructions to run Portability Analyzer.

1.Run PortabilityAnalyzer.exe (https://github.com/Microsoft/dotnet-apiport-ui/releases/download/1.1/PortabilityAnalyzer.zip)

2.In the Path to application text box enter the directory path to your Windows Forms or WPF app (either by inserting a path string or clicking on Browse button and navigating to the folder).

3.Click Analyze button.

4.After the analysis is complete, a report of how portable your app is right now to .NET Core 3.0 will be saved to your disc. You can open it in Excel by clicking Open Report button.

NET Portability Analyzer to determine if there are any APIs your application depends on that are missing from .NET Core. If there are, you need to refactor your code to avoid dependencies on APIs, not supported in .NET Core. Sometimes it’s possible to find an alternative API that provides the needed functionality.

Migration

1.Replace packages.config with PackageReference. If your project uses NuGet packages, you need to add the same NuGet packages to the new .NET Core project. .NET Core projects support only PackageReference for adding NuGet packages. To move your NuGet references from packages.config to your project file, in the solution explorer right-click on packages.config -> Migrate packages.config to PackageReference…..

2.Migrate to the SDK-style .csproj file. To move my application to .NET Core, first I need to change my project file to SDK-style format because the old format does not support .NET Core. Besides, the SDK-style format is much leaner and easier to work with.Make sure you have a copy of your current .csproj file. Replace the content of your .csproj file with the following.

For WinForms application:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
</Project>

For WPF application

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <UseWPF>true</UseWPF>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
</Project>

3.Move from .NET Framework to .NET Standard or .NET Core. To do so, replace this

<TargetFramework>net472</TargetFramework>

with

<TargetFramework>netstandard2.0</TargetFramework>

or

<TargetFramework>netcoreapp3.0</TargetFramework>

4.In the project file copy all external references from the old project, find the proejct reference using old csproj file relpace this. for example:

<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />

to .csproj file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
</Project>

<ItemGroup>
     <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>

Shrink answered 14/10, 2019 at 5:10 Comment(2)
In other words, converting from .Net Framework to .Net Core is about as easy as converting a banana into a Ford FocusPetrina
Works fine. Also change Microsoft.NET.Sdk to Microsoft.NET.Sdk.WindowsDesktopRalfston
R
1

Microsoft released a new Upgrade Assistant tool that will migrate your .NET Framework projects to .NET 5. After migration you can change the TargetFramework in your csproj files to whatever version of .NET you want.

I ran the following commands to install the tool:

dotnet tool install -g try-convert
dotnet tool install -g upgrade-assistant

Then to use it:

upgrade-assistant .\MyProject.csproj
Rave answered 2/3, 2021 at 11:13 Comment(0)
A
0

Maybe in some cases brutal force migration (mentioned in OP) is indeed easiest especially when there is 3rd party libaries that can't be processed by tools automatically.

My Winforms (.NET 4.6.2 with VS2019) exampe:

(1) Create new VS2019 .net core 3.0 WinForm project.

(2) Copy and overwrite every file except for the .csproj and .csproj.user from the old project to the new project folder.

(3) VS2019 somehow add all the copied files to the new project automatically (in this case some file not included in the old project need to be removed manually). If not, add them to the project.

(4) Per the errors in the new project, add missing references.

(5) Some code need to be modified manually such as MySql.Data.MySqlClient -> MySqlConnector.

(6) Upgrade to VS2019 16.8 for support for Form editor with .NET core.

Auria answered 7/1, 2021 at 4:56 Comment(0)
S
0

I know this is an old post but I was trying to upgrade a class library that references 4.7.8 winforms to .netcore 3.0. I'm using visual studio 2022 and the upgrade assistant.

  1. Upgrade all nuget packages to the latest versions
  2. Fix any errors until the project rebuilds cleanly
  3. Use the upgrade assistant (upgrade in the context menu of the project) to the lowest .NET version available (in my current case .NET 5.0).
  4. Clean project
  5. Change the target framework to .NETCore 3.0 in the properties window.
  6. Rebuild

In my case it rebuilt cleanly in .NETCore 3.0.

Scofflaw answered 16/6 at 5:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.