Migrating ASP.NET WebForms From C# 7.3 To C# 11

Microsoft launched C# (C Sharp) 11 on November 2022 with many new features.

I'll guide you on migrating your legacy WebForms Apps with c# 7.3 as default.

This article does not teach c# but how to use the last version of WebForms Apps.

Some features from c# 11 will work only with .NET 5/6/7, but

You can use new features like Raw String Literals and File Scoped. Here is the complete list of c# 11.

You can also use the improvements from c# 8, 9, and 10!

WOW!

Like static local functions, using declarations, nullable from c# 8;

Record and Global Usings from c# 10;

Init only setters, lambda discard parameters.

You can read about these features here.

Attached you can find the project used for this demonstration working that you can see in detail.

Let's do it!

Steps to Migrate

Tip: If you are using Git, create a new branch. If not, do a backup before doing this.

1) Unload your .CSPROJ and add <LangVersion>11.0</LangVersion> on PropertyGroup:

Migrating ASP.NET WebForms From C# 7.3 To C# 11

After that, reload the project!

2) Change your web. Config like that:

Migrating ASP.NET WebForms From C# 7.3 To C# 11

3) Open the NuGet packages; check "Include prerelease" and select the last prerelease, 4.1.

Migrating ASP.NET WebForms From C# 7.3 To C# 11

4) Upgrade to .NET Framework 4.8

Migrating ASP.NET WebForms From C# 7.3 To C# 11

And this is it!

Your project will recognize c# 11!

Migrating ASP.NET WebForms From C# 7.3 To C# 11

Let's see in action:

Migrating ASP.NET WebForms From C# 7.3 To C# 11

The benefits are enormous. In my legacy projects, after migrating the c# code, the solution becomes faster than ever.

I hope you appreciate the article and have the same good experience as I had with c# 11!.


Similar Articles