DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Build a Simple Chat Server With gRPC in .Net Core
  • Penetration Testing: A Comprehensive Guide
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • What Is Pen Testing?

Trending

  • Understanding Java Signals
  • The Role of Functional Programming in Modern Software Development
  • Apache Doris vs Elasticsearch: An In-Depth Comparative Analysis
  • Unlocking AI Coding Assistants Part 1: Real-World Use Cases
  1. DZone
  2. Coding
  3. Languages
  4. Migrating ASP .NET Core 3.1 Web Application to ASP .NET Core 6

Migrating ASP .NET Core 3.1 Web Application to ASP .NET Core 6

.NET 6 is the way forward for solutions built using .NET technology stacks. Explore a step-by-step approach to migrating ASP .NET Core 3.1 to ASP .NET Core 6.

By 
Jawad Hasan Shani user avatar
Jawad Hasan Shani
DZone Core CORE ·
Sep. 06, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
5.0K Views

Join the DZone community and get the full member experience.

Join For Free

.NET 6 unifies the .NET platform for the future. It also introduces plenty of exciting new features along the way. It has achieved the one .NET Vision of Microsoft and also opens up new horizons for existing .NET developers. Improved performance, C# 10 features, and hot-reload are just a few of the reasons you would want to transition to .NET 6 and ASP .NET Core 6.

You can check the official ASP.NET Core 6.0 documentation for more details about what’s new in ASP .NET Core 6.

Our focus in this post is to see a simple process of migrating from ASP .NET Core 3 to ASP .NET 6. In later posts, I’ll cover the new features of .NET 6.

Sample Application

I’ll be using an existing web application that is developed using ASP .NET Core 3.1. It has a very common web application structure and is written around the accounting domain. It has the typical UI (Angular) and API (ASP .NET Core 3.1) and uses Postgres for Data Layer.

Here is how the solution looks in Visual Studio.

Solution in Visual Studio

The source code of this application is available on this Git repo (master branch). You can also check out the deployed application.

Deployed application dashboard

This application also uses the AWS Serverless template (it can be deployed as a serverless Lambda function on AWS). If you are not using AWS Serverless, you can simply ignore this detail.

You can use your own application code and the principles will be the same.

In this post, we will be upgrading the backend of our solution to .NET 6.

Migration Steps

Here are the steps which we will take for the migration process:

  • Install Visual Studio 2022 (this also installs/upgrades SDK).
  • Upgrade TargetFramework in our solution.
  • Update NuGet Packages.
  • Build and test.

In the next sections, we will see all of these steps to migrate our solution to .NET 6.

Installing .NET 6

You can download and install standalone .NET SDK or you can just download and install Visual Studio 2022 and it will automatically install .NET 6 as part of its installation. Also, select Web workload during installation.

Following screenshot shows the installation of Visual Studio 2022, Community Edition:

Visual Studio Installer

Once Visual Studio is installed, you can use the following commands for some details:

Details of commands for Visual Studio

I also installed AWS Toolkit for Visual Studio. Again, you can skip this if not using AWS for .NET.

Open .NET Core Solution in Visual Studio

Once Visual Studio 2022 installation is done and .NET 6 is installed, I opened the ASP .NET Core 3 solution in Visual Studio 2022 and encountered the following notice. Click Install, and it will install the components required.

Install individual components

As you can see, that solution contains different projects arranged in layers for different application concerns:

  • AccountingBook.Core (standard library, domain model)
  • AccountingBook.Data (standard library, entity framework data-layer)
  • AccountingBook.Web (ASP .NET Core 3.1 web API)

I will not go into the details of the application code, but if you are interested in how the application is built, details can be found in the book "Build Accounting Application Using .NET Core, Angular and Entity-Framework."

Now, if we want, we can run our application, and the following picture shows that it is working as expected:

Application running as expected

Next, we will migrate one by one all projects in the solution to .NET 6.

Migrating AccountingBook.Core Project (Standard Library)

Let's start with the AccountingBook.Core project, as it has no dependency on other projects, so it is the simplest to migrate.

Open .csproj file of the project and change it as follows:

AccountingBook.Core.csproj changes

That’s all we needed to do to migrate the library project. We can test by building this project in Visual Studio.

Migrating AccountingBook.Data Project (Standard Library)

This is also a standard library project, but it references AccountingBook.Core project (which we already migrated to net6.0), and it also has some NuGet packages, including Entity Framework Core.

In the same process, let's open up the .csproj file in visual studio for this project:

Update NuGet packages

So, we need to update the TargetFramework to net6.0, which we can do simply by editing the file directly as we did with the previous project.

However, to update NuGet packages, I liked to use Visual Studio’s package-manager window for the project, as it provides more details. The following picture shows packages being updated:

Update all packages

With these changes (TargetFramework and NuGet packages update), migration is done for this project. We can test by building this project in Visual Studio.

Here is how the .csproj file looks after the update:

.csproj file after the update

Migrating AccountingBook.Web Project (Web API)

This project references both AccountingBook.Core and AccoutingBook.Web projects, along with its own packages. However, the process is almost identical to what we did in previous sections.

Here are the .csproj files for the web project:

 .csproj files for the web project

Following the same process, we will first upgrade the TargetFramework to net6.0 and then use package-manager window to update packages.

Update all packages

Here is how the .csproj file looks after the updates:
.csproj file after the updates

We can now build and run the solution to check that it is working as expected after the upgrade.

Migrating AWS Serverless Lambda to .NET 6 Runtime

You can skip this section if you are not using AWS Serverless Lambda.

AWS covers .NET 6 upgrade details in this AWS Compute Blog post along with the steps required to migrate as shown. Following is what we need to do for the migration of .NET Lambda functions to .NET 6 runtime:

  1. Open the aws-lambda-tools-defaults.json file, if it exists:
    1. Set the function-runtime field to dotnet6.
    2. Set the framework field to net6.0. If you remove the field, the value is inferred from the project file.
  2. If it exists, open the serverless.template file. For any AWS::Lambda::Function or AWS::Servereless::Function resource, set the Runtime property to dotnet6.

aws-lambda-tools-defaults.json Files

aws-lambda-tools-defaults.json file: no schema selected
aws-lambda-tools-defaults.json file: serverless.template

With these changes done, we can build the project locally, and once verified, the solution can be deployed using AWS Serverless Lambda:

Publish AWS Serverless Application

Once deployed, we can see from the AWS web console that the Lambda function is updated to .NET6 runtime as well:

Lambda function is updated to .NET6 runtime

Additionally, here we can see that the migrated application is up and running:
Migrated application is up and running

Migration Notes

As you may have noticed, during the migration of the solution, I did not change any of the application code and still was able to migrate the solution with ease. This is due to the fact that most structural changes in .NET 6 are optional, so you can decide later one-by-one which areas you want to change.

Even without doing any structural changes, our migrated application will still benefit from the platform upgrade, such as in performance.

Summary

.NET 6 is the way forward for solutions built using .NET technology stacks. In this post, we saw that migrating an ASP .NET Core 3.1 Web API project to a newer .NET version is a straightforward process and it doesn’t require us to do many changes to our application.

We also saw that with simple changes, AWS serverless Lambda was easy to upgrade to .NET6 runtime as well.

Even without doing any code changes to our application, the updated solution will have performance benefits, and later as we progress, we can refactor different areas of our application with new changes offered by the framework.

You can download the updated application code from the dotnet6 branch of the Git repository linked earlier in this article. 

Let me know if you have some comments or questions. Until next time, Happy Coding.

Active Server Pages Web application application .NET

Published at DZone with permission of Jawad Hasan Shani. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Build a Simple Chat Server With gRPC in .Net Core
  • Penetration Testing: A Comprehensive Guide
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • What Is Pen Testing?

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!