In this post, we'll look at the steps necessary to migrate a Visual Basic 6 app to .NET Core 3.0.
We will use our reference app Salmon King Sea Food available on Github.
This guide explains the steps necessary to port apps in general and will walk you through the changes you need to apply to the SKS sample.
Migrating to .NET Core is great because once converted to a .NET Core application, apps can now be extended with everything new that .NET will include in the future.
Step 0 – Prerequisites
To port your desktop apps to Core, you’ll need .NET Core 3 and Visual Studio 2019.
You also need a trial version of the VBUC
Step 1 – Migrate from VB6 to .NET Framework
Step 2 – Migrate the project to a SDK-style .csproj
It is usually easier to start with the VS templates. So let's try that.
- Open Visual Studio 2019 and Select Create New Project
- Create a new NetCore Console App
- Set the project name and location. For example SKS for our SKS app
In Solution Explorer remove all project file items and right-click on your project (not on the solution!) and select the Edit Project File option.
Now we will edit the project file, to adjust it as a proper WinForms NetCore3 app. So remove the contents of project file and replace it with:
The UseWindowsForms and OutputType property set the project as a .NET Core 3 windows forms app. Notice that TargetFramework which is now netcoreapp3.0.
The <GenerateAssemblyInfo>false</GenerateAssemblyInfo> is set because we will use the AssemblyInfo from the old project.
Step 4 – Change nugets
Your old application relied on nugets targeting .NET Framework. The VBUC team has already new nugets that will help you transition to .NET Core.
Add these references:
For the SKS those are all the Nugets you need, but for other applications you might need some additional references.
The SKS uses OLEDB so make sure that you have the OLE DB Jet Engine Installed. Also this engine is for x86 or x64. So for example if you want to keep using x86 then add this to your project.
Step 5 – Copy your code
Now go back to the Solution Explorer and right-click on your project (not on the solution!) and select the Open Folder in File Explorer option.
Copy all the source files from the output of the VBUC to this folder.
Step 6 – Compile and enjoy!
The VBUC does not currently generate projects targeting .NET Core 3 but as you can see is not that difficult to adjust the output to start enjoying .NET Core 3.