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.
[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
Please follow this step:
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.
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With