Port legacy VB.NET applications to .NET 6.0 with Porting Assistant for .NET
Since its release in 2002, Visual Basic .NET (VB.NET) has been a popular choice for software developers creating Windows-based applications. With the release of .NET 6.0, some exciting changes are available for developers. This version of .NET boasts some amazing features that are sure to make your applications faster, more reliable, and easier to maintain. But what if you have legacy VB.NET Framework applications that you need to port over to .NET 6.0 to take advantage of these benefits? Don’t worry – the Porting Assistant for .NET can help!
AWS recently announced support of porting .NET Framework applications written in VB.NET to .NET 6.0 with Porting Assistant for .NET. With this release, Porting Assistant for .NET translates VB.NET class libraries, web APIs, and console applications to .NET Core 3.1, .NET 5, or .NET 6 to simplify the modernization of legacy .NET Framework applications written in VB.NET. This blog post will provide you with step-by-step guidance on how to port your legacy VB.NET applications to the latest version of .NET
Porting Assistant for .NET is an open-source analysis tool that reduces the manual effort and guesswork involved in porting .NET Framework applications to .NET 6, helping customers move to Linux faster. It identifies incompatibilities with .NET 6.0, generates an assessment report with known replacement suggestions, and assists with porting. Refer to the documentation and launch blog for Porting Assistant for .NET to familiarize yourself with how to use Porting Assistant for .NET.
Challenges in porting legacy applications to the latest version of .NET
A few years back, while working as a consultant, I helped one of my enterprise customers modernize their legacy technology platform and migrate it to AWS. We decided to port the entire technology platform to the latest release of .NET Core. My team spent more than a few weeks identifying compatible NuGet packages, searching the internet to find replacements for the incompatible APIs, etc. Any software professional who has spent time porting a legacy application to the latest version of .NET can resonate with my experience. So, in 2020, when I heard the announcement of the Porting Assistant for .NET for C#, I got very excited. I wish I had this tool when I was a consultant helping my customers port their applications. It could have cut down my team’s efforts from weeks to days.
Step-by-step guide to port VB.NET applications to .NET 6.0
In this tutorial, due to its popularity and familiarity in the developers’ community, I am using release-3.80 of the nopCommerce application converted into VB.NET locally.
For this tutorial, you will need:
Step 1: Download release-3.80 of the nopCommerce application
You can download release-3.80 of the nopCommerce application locally using the following git commands:
1. git clone https://github.com/nopSolutions/nopCommerce.git 2. git checkout release-3.80
Step 2: Convert the nopCommerce solution to VB.NET
Release-3.80 of the nopCommerce application is implemented in C# using .NET Framework 4.5.1. So first, you will need to convert it from C# to VB.NET using the Code Converter tool.
- Download and install the Code Converter extension from the Visual Studio Marketplace, as shown in Figure 1.
Figure 1. Code Converter Extension
- Right-click on the nopCommerce solution and select Convert to VB, as shown in
Figure 2. Convert to VB menu option
- It will take a few minutes to convert the nopCommerce solution to NET. After a successful conversion, Porting Assistant for .NET will reload the solution with the converted VB source files and projects.
Step 3: Running a compatibility assessment
Next, run a compatibility assessment on the nopCommerce solution using the following steps.
- Launch the Porting Assistant for .NET and click Get started to run an assessment on the source project, as shown in Figure 3.
Figure 3. Get Started button to initiate assessment
- Choose to Assess a new solution and select sln from your local drive, as shown in Figure 4.
Figure 4. Option to select new solution for assessment
- Click Assess to begin the assessment as shown in Figure 5. Due to the size of the nopCommerce solution, it will take a few minutes to finish.
Figure 5. Assess option to begin the assessment
Step 4: Review the assessment results using the dashboard
The Porting Assistant for .NET dashboard offers a quick summary of assessment results, including incompatible packages and APIs, in addition to the number of projects ported so far if you have started porting the projects.
Figure 6 shows that 0 projects out of 35 have ported so far. A total of 52 NuGet packages are incompatible out of 56, and 3289 APIs are incompatible out of 7167.
Figure 6. Porting Assistant Dashboard
Step 5: Breakdown of incompatibilities by project
Porting Assistant for .NET offers a drill-down graphical interface so you can click on the solution to examine the breakdown of incompatibilities by project, as shown in Figure 7.
Figure 7. Assessment overview
Step 6: Different assessment views
Porting Assistant for .NET offers five different assessment views: Projects, Project references, NuGet packages, APIs, and Source Files, as shown in Figure 8. These views help developers analyze the assessment results from different perspectives. The NuGet packages view provides details of the compatible and incompatible dependencies and suggested replacements if available. Similarly, the APIs view lists the incompatible APIs, what package they are in, and how many times they are referenced. Finally, you can deep dive into the Source files view and navigate to the exact source line where the particular API is being called.
Figure 8. Various assessment views
Step 7: Use Project references view to start
My favorite assessment view is the Project references view, which gives you a visual representation of project dependencies. It helps developers quickly decide which project(s) they should start porting to minimize the overall effort and see the results quickly.
For example, you can see in Figure 9 that most of the projects depend on the Nop.Core library, so it makes sense to port it first. In addition, it will help you resolve maximum compatibilities issues in less time.
Figure 9. Graphical view of projects dependencies
Step 8: Port the Project using assisted porting
While you can select all the projects in the Projects view using the checkmarks on the right side next to each project, for simplicity, choose only Nop.Core and start porting it.
- Click on Port Project after selecting the checkmark next to Core, as shown in Figure 10.
Figure 10. Assessment overview
- Next, you will be prompted to choose the porting location, as shown in Figure 11. You have the option to “Modify source in place” or “Copy to new location.” If you have cloned the repository, select the “Modify source in place” option to compare changes using the Git version control system.
Figure 11. Select how you want to store the modified solution
- Depending upon the size of the project and the number of incompatibilities, porting might take a few minutes. Once the porting is completed, you will see the notification at the top, as shown in Figure 12.
Figure 12. Updated Porting Assistant Dashboard after assessment is done
Step 9: Build the project and examine the code changes
Once the porting is done, the very first thing you should do is compile and build the project to make sure you don’t get any build errors.
The suggestion engine behind the Porting Assistant for .NET is designed to learn and improve results over time as customers opt-in to sharing their telemetry. The data models behind the engine, which result from analyzing hundreds of thousands of unique packages with millions of package versions, are available on GitHub.
Let’s examine the code changes done by the Porting Assistant for .NET on the Nop.Core library project and related source files:
- It has deleted the config file, as shown in Figure 13.
Figure 13. Deleted packages.config
- Also, it has added the compatible NuGet packages to the Core.vbproj file, as shown in Figure 14.
Figure 14. Updated project file with the compatible NuGet packages
Suppose there is no suggested replacement for a different package version. In that case, you need to open a source editor and update the code to use a different API or approach to fix it manually. It will be an iterative process.
You need to repeat the process for the rest of the projects to finish porting the nopCommerce solution. You can use the Project references graphical view to prioritize which project should port next based on the number of projects dependent on it.
This blog post showcased how the Porting Assistant for .NET can help developers significantly reduce the effort to port legacy .NET Framework applications written in VB.NET to .NET 6.0. Once the application is ported to .NET 6.0, developers can continue the modernization process by containerizing it, hosting it on Amazon Elastic Container Service or Amazon Elastic Kubernetes Service, or running serverless containers using AWS Fargate. Also, you can move from Windows containers to Linux containers and reduce the cost of hosting .NET applications on AWS, improve application scaling and performance, and reduce licensing spending.
AWS can help you assess how your company can get the most out of cloud. Join the millions of AWS customers that trust us to migrate and modernize their most important applications in the cloud. To learn more on modernizing Windows Server or SQL Server, visit Windows on AWS. Contact us to start your modernization journey today.