The .NET Stacks #25: .NET 5 officially launches tomorrow

This week, .NET 5 ships, and are C# 9 records actually immutable by default?

Dave Brock
Dave Brock

With .NET 5 shipping this week, it’s going to be such a release.

On tap this week:

  • .NET 5 officially launches tomorrow
  • Are C# 9 records actually immutable by default?
  • Last week in the .NET world

.NET 5 officially launches tomorrow

After eight preview releases, two release candidates, and some tears—by me, working on the early preview bits—it’s finally happening: .NET 5 ships tomorrow. Of course, the release candidates shipped with a go-live license but everything becomes official tomorrow. You’ll be able to download official bits and we might even see it working with Azure App Service (no pressure). There’s also .NET Conf, where you’ll get to geek out on .NET 5 for three straight days.

It’s been a long time coming—and it feels a bit longer with all this COVID-19 mess, doesn’t it? Even so, the “Introducing .NET 5” post hit about 18 months ago—and with it, the promise of a unified platform (with Xamarin hitting .NET 6 because of pandemic-related resourcing constraints). We’re talking a single .NET runtime and framework however you’re developing an app, and a consistent release schedule (major releases every November).

Of course, this leads to questions about what it means to say .NET Framework, .NET Standard, and .NET Core—not to mention how the support will work. I covered those not-sexy-but-essential questions two weeks ago.

Since I started this newsletter in May (we’re at Issue #25!), we’ve been dissecting what’s new week by week. (You can look at the archives on my site.) For a condensed version, here’s my favorite things about .NET 5—both big and small. (This is a little like talking about your favorite song or movie, so your opinions might differ.)

Custom JSON console logger

ASP.NET Core now ships with a built-in JSON formatter that emits structured JSON logs to the console. Is this a huge change? No. Will it make my life easier on a daily basis. You know it.

Enhanced dotnet watch support

In .NET 5, running dotnet watch on an ASP.NET Core project now launches the default browser and auto-refreshes on save. This is a great quality-of-life developer experience improvement, as we patiently await for this to hit Visual Studio.

Open API spec on by default for ASP.NET Core projects

When you create a new API project using dotnet new webapi, you’ll see OpenAPI output enabled by default—meaning you won’t have to manually configure the Swashbuckle library and the Swagger UI page is enabled in development mode. This also means that F5 now takes you straight to the Swagger page instead of a lonely 404.

Performance improvements

If you have some time to kill and aren’t scared off by low-level details, I’d highly recommend Stephen Toub’s July post on .NET 5 performance improvements. In short, text operations are 3x-5x faster, regular expressions are 7x faster with multiline expressions, serializing arrays and complex types in JSON are faster by 2x-5x, and much more.

EF Core 5 updates

EF Core 5 is also shipping with a ton of new features. Where to begin? Well, there’s many-to-many navigation properties (skip navigations), table-per-type inheritance mapping, filtered and split includes, general query enhancements, event counters, SaveChanges events, savepoints, split queries for related collections, database collations, and … well, check out the What’s New doc for the full treatment.

Single file apps

Single-file apps are now supported with .NET 5, meaning you can publish and distribute an app in a single executable. Hooray.

Blazor updates

.NET 5 ships with a ton of Blazor improvements, including CSS isolation, JavaScript isolation, component virtualization, toggle event support, switching WebAssembly apps from Mono to .NET 5, lazy loading, server pre-rendering, and so on.

C# 9

I’m super excited for the release of C# 9, especially the embracing of paradigms common in functional programming. With init-only properties and records, C# developers have the flexibility to easily use immutable constructs in a mutable-by-design language. It might take some getting used to, but I love the possibilities. I see a lot of promise in keep the real-world object modeling, but also introducing immutability where treating objects as data makes sense.

(There’s also great improvements with top-level programs, pattern matching, and target typing.)

Are C# 9 records actually immutable by default?

Speaking of records, there seems to be some confusion on if C# 9 records are immutable by default. The answer is: yes, and no. Records are immutable by default when using positional arguments. When you want to use them with object initializers, they aren’t—which makes sense, since initializers are more flexible in how objects are constructed.

Feel free to check out my post for the full details.

Happy birthday, Dad

Someone has turned a lucky … um … well, numbers don’t matter, do they? Happy Birthday, Dad. You can thank him for … waves hands … all this. I’m not sure what I’d be doing without him encouraging my nerdy tendencies during my most awkward years, but I’m glad I’ll never have to find out. Have a good day, mister.

When I said I like to wear many hats, I didn’t mean this one.

Picture with mom

(Don’t worry, this is the last birthday wish. Back to regularly scheduled programming.)

🌎 Last week in the .NET world

🔥 The Top 3

📢 Announcements

📅 Community and events

😎 ASP.NET Core / Blazor

⛅ The cloud

📔 Languages

🔧 Tools

📱 Xamarin

🎤 Podcasts

The .NET Rocks podcast discusses Cake 1.0 with Mattias Karlsson.

🎥 Videos

.NET Stacks