.NET on AWS Blog

Port .NET Framework workloads to Linux with Amazon Q Developer, Part 1: Class libraries

Introduction

In the .NET world, the modernization process for .NET Framework applications can be complex, presenting significant challenges for enterprise software development teams. Organizations with extensive .NET Framework codebases face critical decisions about migrating traditional applications to modern .NET and Linux, including careful analysis of dependencies and how to handle compatibility constraints. Existing libraries may rely on Windows-specific APIs and Framework-specific features that aren’t directly portable to .NET Core/. NET. This can necessitate code refactoring and substitution of library packages.

Enter Amazon Q Developer, a generative AI-powered assistant which leverages advanced .NET transformation capabilities to streamline the migration process, offering intelligent code analysis, automated transformation suggestions, and comprehensive compatibility assessments. By intelligently identifying potential migration challenges, recommending best practices, and providing real-time guidance, Amazon Q Developer significantly reduces the complexity and risk associated with modernizing .NET Framework projects.

Amazon Q Developer’s .NET transformation capabilities currently can port several kinds of projects, including class libraries, WebAPIs, WCF services, MVC back ends, console applications, and test projects. Each post in this series will focus on a different project type. In this post, I’ll give a walkthrough of porting a .NET Framework class library.

Prerequisites

For this tutorial, you should:

  1. Install Visual Studio 2022 
  2. Install and set up AWS Toolkit for Visual Studio
  3. Subscribe to Amazon Q Developer Pro
  4. Set up Amazon Q Developer in the toolkit
  5. Download or clone the sample application from GitHub

Understanding the Sample Application

To illustrate Amazon Q Developer transformation of a class library, we’ll use Faker.Net as a sample application, a public GitHub project with an MIT license. Faker.Net is a powerful .NET Framework 4.0 class library that allows developers to generate large volumes of realistic fake data for testing, development, and demonstration purposes. It provides a wide range of data types including names, addresses, phone numbers, and more, making it an invaluable tool for populating databases, creating mock objects, and stress-testing applications with lifelike data sets.

Below is the output of the Faker sample application which generated a fake address.

Figure 1: Faker Console

Figure 1: Faker Console

The solution contains three projects: Faker.Net, a class library project, a sample console application, and a test project for validating various use cases.

When first opening this traditional application in Visual Studio 2022, the IDE suggests upgrading from .NET Framework 4.0 to .NET Framework 4.8.

Figure 2: Verify .NET Framework version

Figure 2: Verify .NET Framework version

After completing the upgrade, you can verify the successful migration to .NET Framework 4.8 by checking the project properties.

Figure 3: Verify .NET Framework version

Figure 3: Verify .NET Framework version

Run the console application to see the library work. You will want to verify the same behavior after porrting to confirm functionality is intact.

Transforming the application

Step 1: Verify AWS Toolkit for Amazon Q is Enabled

Access the Getting Started screen to confirm that you’re properly authenticated to both Amazon Q developer and AWS Toolkit. The AWS Toolkit screen should display the authentication status.

Figure 4: Verify Amazon Q is enabled

Figure 4: Verify Amazon Q is enabled

Before starting a transformation, make sure to open a .cs file first to activate the Amazon Q development agent. Otherwise, you will encounter the error below.

Figure 5: Open code file

Figure 5: Open code file popup

Step 2: Begin porting

Right click on the Faker.Net solution and select Port solution with Amazon Q Developer.

Figure 6: Transform solution

Figure 6: Transform solution

On the Port solution dialog, confirm the .NET target version and select Start to transform your Faker.Net project.

Figure 7: Port solution

Figure 7: Port solutionAmazon Q Developer initiates the transformation process by first performing a local build of your code to verify the build and proper configuration. Once verified, your code is uploaded to a secure AWS build environment where Amazon Q Developer conducts a thorough analysis to identify required updates for porting your application.

You can monitor the transformation job progress in the Amazon Q Developer Code Transformation Hub panel.

Figure 8: Transformation Plan

Figure 8: Transformation Plan

During analysis, Amazon Q Developer organizes your .NET solution into Code groups – logical units consisting of a project and its associated dependencies that together form a buildable component like a DLL or executable. Importantly, even if you’ve only selected specific projects for transformation, Amazon Q Developer automatically includes and transforms all necessary dependencies to ensure your final transformed application is fully buildable and functional.

The Transformation Process

After analyzing your code, Amazon Q Developer generates a transformation plan that details all proposed changes to be implemented. This plan includes a detailed breakdown of code groups and their associated dependencies that will undergo transformation.

The process unfolds across four sequential steps:

  1. Amazon Q Developer builds your projects locally to validate their integrity.
  2. Initiates and awaits the transformation job startup.
  3. Generates a detailed code transformation plan.
  4. Executes the transformation plan to completion.

This systematic approach ensures a thorough and well-organized transformation of your codebase.

Transformation Summary

To protect your working environment, any code modifications are performed within a secure sandbox environment, ensuring your original working directory remains untouched.

Upon completion of the transformation job, Amazon Q Developer provides a comprehensive code transformation summary. You can also download Linux readiness report with warnings and recommendations.

Figure 9: Transformation Summary

Figure 9: Transformation Summary

Review and accept code changes

To review and accept these changes, you can access the diff view by selecting the View diffs button in the Transformation summary tab. The Amazon Q Developer Code Transformation Hub panel, located at the bottom of the screen, will display all modified files for your review.

Figure 10: Apply code changes

Figure 10: Apply code changes

In this particular transformation, the Faker.Net.csproj project file underwent several updates, including a conversion to the new Project format, removal of legacy Reference/Compile Include lines, and an update to the target framework version.

Figure 11: View project changes

Figure 11: View project changes

In this update to Internet.cs, Amazon Q Developer performed basic code refactoring, including the optimization of variable declarations and method parameter restructuring.

Figure 12: View code changes

Figure 12: View code changes

In this update to Locale file En.cs, Amazon Q Developer updated the legacy namespace to the modern System.Text.Json serialization library.

Figure 13: View code changes

Figure 13: View code changes

Review all the remaining changes and If you’re comfortable with the changes, accept them by choosing Select all and then Apply changes.

After accepting the transformation changes and reloading the solution, you’ll find your class library project has been successfully updated.

Figure 14: Verify target framework

Figure 14: Verify target framework

Run the console project again to verify the project builds and its functionality is still intact.

Conclusion

In this first post of the series, I showed how to port a class library. In the remainder of the series, we will explore other supported project types.

Amazon Q Developer simplifies .NET Framework modernization by providing intelligent code transformation to modern cross-platform .NET that can run on Linux. The tool analyzes complex class libraries, identifying platform-specific dependencies, suggesting code and package refactoring, and automating many common migration challenges. By leveraging Amazon Q Developer’s advanced AI capabilities, development teams can efficiently modernize their .NET class libraries, ensuring compatibility, performance optimization, and seamless transition to cross-platform .NET environments.

Call to Action

  1. Explore Amazon Q Developer transform for transforming .NET as well as mainframe, VMware and Java workloads.
  2. Configure Amazon Q Developer Pro: Set up subscriptions, manage user access, and resolve common subscription issues to ensure seamless team adoption.
  3. Remember to always test thoroughly and validate the migrated application in a staging environment before deploying to production.
Pavankumar Kasani

Pavankumar Kasani

Pavankumar Kasani is an AWS Solutions Architect based out of New York city. He is passionate about helping customers to design scalable, well-architected and modernized solutions on the AWS Cloud. Outside of work, he loves spending time with his family, playing cricket, table tennis, and also testing out new recipes in the kitchen.

Ty Augustine

Ty Augustine

Ty is a Microsoft Specialist Solutions Architect focused on .NET, SQL Server and Containers. Ty is based in NYC and works closely across diverse industries to accelerate migrations and modernization to the AWS Cloud. Before coming to AWS, Ty was a Microsoft stack software architect for 20+ years.