0

.NET 8.0 Features, Highlights, & Lowlights

 7 months ago
source link: https://devm.io/dotnet/dotnet-8-0-highlights-001
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

The differences between Release Candidate 1, Release Candidate 2 and the final version

.NET 8.0 Features, Highlights, & Lowlights


.NET 8.0 was released on November 14, 2023. However, use in production has been possible since September, since the Release Candidate 1 version had a go-live license from Microsoft. In this article, Holger Schwichtenberg reports what’s happened between the preview phase and the release.

The Release Candidate 1 version was released on September 12, 2023, followed by Release Candidate 2 on October 10, 2023. The final version was released on November 14, 2023 shortly before 6 p.m. as part of the virtual .NET Conf 2023.

You can find the listings for this article in our GitHub repository.

The downloads (one SDK and three runtimes) for .NET 8.0 are available here. At least Visual Studio 2022 version 17.8 is required, which also had a new stable release published on November 14, 2023. A preview version for 17.9 is already available, which includes a scaffolding function for a Blazor CRUD interface (with the QuickGrid component from Microsoft) based on Entity Framework Core for the first time.

As announced, .NET 8.0 will receive Long Term Support (LTS) for three years, until November 2026. The list of breaking changes compared to .NET 7.0 has grown significantly in recent months.

Name changes for new Blazor features

Let me briefly summarize the Blazor United strategy:

  1. Blazor United introduces a purely server-side rendering for Blazor called Blazor SSR. Blazor SSR is a multi-page web app, not single-page. It can be seen as a better alternative to ASP.NET Core MVC and ASP.NET Razor Pages since Blazor SSR has a real component model, better Razor syntax, and partial page updating (enhanced navigation and streaming).
  2. Blazor SSR forms the start code for Blazor Server and ASP.NET Core hosted Blazor WebAssembly applications instead of Razor Pages.
  3. In a Blazor SSR application, individual web pages can run with Blazor Server or Blazor WebAssembly.
  4. With the new auto mode, a page can be rendered via Blazor Server and then be transferred to Blazor WebAssembly.

In the preview phase, SSR stood for Server-side Rendering. Microsoft changed the name to Static Server Rendering to better differentiate the term from Blazor Server. However, the new term Static Server Rendering comes close to Static Site Generation (SSG). SSG - the rendering of a complete web application at development time - isn’t offered by .NET 8.0. However, Microsoft is planning it for .NET 9.0. In its preliminary stages, in .NET 8.0 you can already render Razor Components in any .NET application (console, desktop, or WebAPI), for sending e-mails with HTML content.

In the final product, Microsoft no longer uses the generic term "Blazor United" for these new Blazor features. However, it was a good link to the previous reports. Microsoft now simply refers to "Blazor Web Apps".

Consolidating Blazor project templates

Since Preview 7, Microsoft consolidated the project templates for Blazor (as announced). The following Blazor project templates were available in .NET 7.0:

  • BLAZOR SERVER APP
  • BLAZOR SERVER APP EMPTY
  • BLAZOR WEBASSEMBLY APP with the option ASP.NET CORE HOSTED or STANDALONE
  • BLAZOR WEBASSEMBLY APP EMPTY with the option ASP.NET CORE HOSTED or STANDALONE
  • .NET MAUI BLAZOR HYBRID APP

There are still three Blazor project templates for .NET 8.0, but with a different layout:

• BLAZOR WEB APP mit den Render-Modi NONE, SERVER, BLAZOR WEBASSEMBLY und AUTO • BLAZOR WEBASSEMBLY STANDALONE APP • .NET MAUI BLAZOR HYBRID APP

If you look at project templates with the word "Blazor" in Visual Studio (Fig. 1) or via the command line (Fig. 2), you’ll see familiar templates for BLAZOR WEBASSEMBLY, BLAZOR SERVER, and BLAZOR MAUI as well as the new BLAZOR WEB APP. When using the project templates for BLAZOR SERVER, you’ll notice that .NET 8.0 isn’t offered for BLAZOR SERVER in the Visual Studio dialog. These two project templates (and their sister templates with EMPTY in the name) no longer exist in .NET 8.0.

Fig. 1

Fig. 1: Blazor project templates in .NET 8.0 overview

Fig. 2

Fig. 2: Blazor project templates in the .NET 8.0 SDK on the command line

Besides the BLAZOR WEB APP, there’s also a template called BLAZOR WEBASSEMBLY STANDALONE APP. The stand-alone app is an extract of the previous project template BLAZOR WEBASSEMBLY APP. It creates a Blazor WebAssembly application that doesn’t rely on ASP.NET Core on the web server and can be available on any (possibly static) web server to be downloaded by the web browser.

There’s also a project template called .NET MAUI BLAZOR HYBRID APP which isn’t affected by these changes.Still, it’s unfortunate that there isn’t a project template for hybrid Blazor applications with Windows Forms and Windows Presentation Foundation (WPF) in the .NET SDK. Figure 3 shows the development of Blazor types and project templates from .NET 7.0 to .NET 8.0.

Fig. 3

Fig. 3: Blazor variants and Blazor project templates before and after .NET 8.0

Many changes in the "Blazor Web App" project template

In .NET 8.0 Preview 3 and 4, you needed to create an ASP.NET Core MVC or Razor Pages project as a starting point for Blazor SSR. But since .NET 8.0 Preview 5 and Visual Studio 2022 17.7 Preview 2, there’s a new project template BLAZOR WEB APP. The current status in Visual Studio 2022 17.8 Preview 4 and .NET 8.0 Release Candidate 2 is shown in Figure 4.

This template was expanded since Release Candidate 1 so it completely replaces the previous templates for web browser applications BLAZOR SERVER APP, BLAZOR SERVER APP EMPTY, BLAZOR WEBASSEMBLY APP and BLAZOR WEBASSEMBLY APP EMPTY. However, Blazor hybrid applications like Blazor Desktop and Blazor MAUI are not covered by the new template.

While there was a series of checkboxes for the selection in Release Candidate 1, there have been two selection lists since Release Candidate 2 (Fig. 4): In the first, users select the interactivity type. In the second, users select whether the interactivity type should be applied to individual pages or the entire application.

Fig. 4

Fig. 4: Settings for the "Blazor Web App" project template

Alternatively, you can create a BLAZOR WEB APP project on the command line. The template is simply called blazor:

dotnet new blazor -o Projektname

When using the dotnet new command line command (Fig. 5), the parameters are --interactivity and --all-interactive. With --interactivity, you have the options None, Server, WebAssembly and Auto. The default LOCATION setting for the command line command is PER PAGE/COMPONENT. This can be extended to the entire application with --all-interactive, which corresponds to the GLOBAL selection in Visual Studio.

Fig. 5: "Blazor Web App" project template with auto mode for the complete application on the command line

If you select PER PAGE/COMPONENT, you’ll receive individual Razor components with annotations. While these annotations were still used in Preview 7:

@attribute [RenderModeServer]
@attribute [RenderModeWebAssembly]
@attribute [RenderModeAuto]

In Release Candidate 2, Microsoft changed them to:

@attribute [RenderModeInteractiveServer]
@attribute [RenderModeInteractiveWebAssembly]
@attribute [RenderModeInteractiveAuto]

Since Release Candidate 2, there are also independent Blazor directives:

@rendermode InteractiveServer
@rendermode InteractiveWebAssembly
@rendermode InteractiveAuto

Since the RTM version, these can be found in the project template (Listing 1).

Listing 1: Counter.razor with the Render-Modus “Server”

@page "/counter"
@rendermode InteractiveServer

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
  private int currentCount = 0;

  private void IncrementCount()
  {
    currentCount++;
  }
}

The new GLOBAL selection in Figure 4 means the render mode isn’t set in individual pages, but in the App.razor file for all pages (Listing 2). With interactivity mode NONE, it makes no difference what you select for INTERACTIVITY LOCATION. From a user experience perspective, this selection field should be grayed out for NONE.

Listing 2: App.razor with the Render-Modus “Server” and “Global”

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <base href="/" />
  <link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
  <link rel="stylesheet" href="app.css" />
  <link rel="stylesheet" href="BlazorAppBSGlobal.styles.css" />
  <link rel="icon" type="image/png" href="favicon.png" />
  <HeadOutlet @rendermode="@RenderMode.InteractiveServer" />
</head>

<body>
  <Routes @rendermode="@RenderMode.InteractiveServer" />
  <script src="_framework/blazor.web.js"></script>
</body>

</html>

Microsoft replaces two lines in App.razor for Blazor WebAssembly and Auto mode:

...
<HeadOutlet @rendermode="@RenderMode.InteractiveWebAssembly" />
...
<Routes @rendermode="@RenderMode.InteractiveWebAssembly" />
...

respectively:

...
<HeadOutlet @rendermode="@RenderMode.InteractiveAuto" />
...
<Routes @rendermode="@RenderMode.InteractiveAuto" />
...

The method names in the start code have also changed. For activating the Blazor Server, you now write:

builder.Services.AddRazorComponents()
  .AddInteractiveServerComponents();
app.MapRazorComponents<App>()
  .AddInteractiveServerRenderMode();

For Blazor WebAssembly, it is:

builder.Services.AddRazorComponents()
  .AddInteractiveWebAssemblyComponents();
app.MapRazorComponents<App>()
  .AddInteractiveWebAssemblyRenderMode()
  .AddAdditionalAssemblies(typeof(Counter).Assembly);

For auto mode, you combine the two:

builder.Services.AddRazorComponents()
  .AddInteractiveServerComponents()
  .AddInteractiveWebAssemblyComponents();
app.MapRazorComponents<App>()
  .AddInteractiveServerRenderMode()
  .AddInteractiveWebAssemblyRenderMode()
  .AddAdditionalAssemblies(typeof(Counter).Assembly);

The AddAdditionalAssemblies() call is new in the BLAZOR WEB APP project template. It ensures that Blazor WebAssembly finds the Razor components...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK