What's New for ASP.NET Core & Blazor in .NET 7
.NET 7 shipped this week, finally unifying separate components into one umbrella development platform that lets developers build all types of apps -- cloud, desktop, mobile, web, AI, IoT and more -- on the same Base Class Library (BCL), runtime and compilers, thus fulfilling Microsoft's long-delayed push toward "just one .NET going forward."
As part of the big release, Microsoft detailed what's new for ASP.NET Core, starting with Blazor, used to create Single Page Applications (SPA). For example, developers can now create Blazor custom elements to dynamically render Razor components from other SPA frameworks including Angular or React. For more on that, see the article, "Custom Blazor Elements No Longer Experimental in .NET 7 Preview 6."
Improvements were also made around WebAssembly (sometimes abbreviated as Wasm), the open source tech baked into client-side Blazor that allows for C# in browser-based web projects by turning C# code into executable assembly-like code.
Also, a .NET 7 release candidate let developers try out early-stage experimental WebAssembly multithreading -- which is actually supposed to be included with .NET 8 next year -- thanks to the aforementioned
wasm-experimental workload. "The
wasm-experimental workload now includes support for multithreaded .NET apps on WebAssembly using Web Workers," Microsoft said in an October preview. "This is a new .NET runtime capability. Multithreading support hasn't been integrated yet into Blazor WebAssembly apps (planned for .NET 8), but you can still try it out in preview form using the experimental WebAssembly Browser App template." For more on that, see the article, "No Need to Wait for .NET 8 to Try Experimental WebAssembly Multithreading."
In other new goodies, the Blazor WebAssembly project template in Visual Studio has a new UI construct that shows the progress of loading an app. The loading screen animation is implemented with two new CSS custom properties -- acting as variables -- that are now part of Blazor WebAssembly. They are used to show the percentage of app files loaded and the percentage of app files loaded rounded to the nearest whole number.
For more on that, see the article, "What's New for Blazor, ASP.NET Core in Latest .NET 7 Preview." And, speaking of Visual Studio, for more on the latest Visual Studio 2022 release, version 17.4, which shipped along with .NET 7, see the article, "Visual Studio 2022 17.4 Now Generally Available."
Speaking of templates, there are new ones for Visual Studio 2022:
- Blazor Server App Empty: An empty project template for creating a Blazor server app that runs server-side inside an ASP.NET Core app and handles user interactions over a SignalR connection. This template does not have any content in it.
- Blazor WebAssembly App Empty: An empty project template for creating a Blazor app that runs on WebAssembly and is optionally hosted by an ASP.NET Core app. This template does not have any content in it.
Microsoft this week explained other Blazor enhancements, including:
Concerning that last item, the lack of native AOT was a longstanding .NET Core issue, with Microsoft in 2020 publishing results of a survey indicating that the lack of AOT was keeping developers from using .NET Core more. Since then, the company has been introducing it in drips and drabs across various properties.
More about mixed-mode AOT, multithreading and more can be found in the article, ".NET 7 WebAssembly Plans: Mixed-Mode AOT, Multi-Threading, Web Crypto."
Meanwhile, Blazor Hybrid, allowing for native apps that can leverage web technologies like HTML and CSS for additional functionality, sees faster performance and improvements around security, along with minor tweaks like the ability to open external web pages in the browser. According to planning documentation, security tweaks were intended to address:
- The need to define what are the threats here
- Rogue-ish third-party component?
- The need to look at the threat models for other native client platforms, e.g. WPF, because we will likely have some subset of the same concerns
- The need to review guidance from docs of each native WebView component for any best practices
You can read more about all that in the article, "What's Coming for Blazor Hybrid in .NET 7."
Along with Blazor and WebAssembly, other parts of the ASP.NET Core web-dev framework that were improved include servers/runtime, minimal APIs, gRPC, SignalR and MVC. Early in the year, Microsoft outlined plans for those properties and more:
- Performance: .NET 6 contained many performance improvements for ASP.NET Core, and we'll do work to make ASP.NET Core even faster and more efficient in .NET 7.
- HTTP/3: HTTP/3 support shipped as a preview feature in .NET 6. For .NET 7, we want to finish it and make it a supported feature that's enabled by default. In future previews, you can expect to see advanced TLS features and more performance improvements in our HTTP/3 support.
- Minimal APIs: Add support for endpoint filters and route grouping as core primitives for minimal APIs. Also simplify authentication and authorization configurations for APIs in general.
- gRPC: We're investing in gRPC JSON transcoding. This feature allows gRPC services to be called like RESTful HTTP APIs with JSON requests and responses.
- SignalR: Add support for strongly-typed clients and returning results from client invocations.
- Razor: We'll make various improvements to the Razor compiler to improve performance, resiliency, and to facilitate improved tooling.
- MVC: Improvements to endpoint routing, link generation, and parameter binding.
- Orleans: The ASP.NET Core and Orleans teams are investigating ways to further align and integrate the Orleans distributed programming model with ASP.NET Core. Orleans 4 will ship alongside .NET 7 and focuses on simplicity, maintainability, and performance, including human readable stream identities and a new optimized, version-tolerant serializer.
As for what was actually included in the final GA release, see the nitty-gritty details in Microsoft's Nov. 8 post and corresponding release notes.
David Ramel is an editor and writer for Converge360.