It’s not hard to see why Microsoft is investing in WebAssembly. It’s a technology that scratches many different itches. It delivers apps to users, adds rich user interfaces to web applications, and even provides a way to manage and update edge devices. By building on widely distributed web technologies and supporting familiar programming languages, it’s a way to run compiled binaries anywhere that you can run a JavaScript engine.

Microsoft has had plenty of experience with common language runtimes like WebAssembly’s. After all, .NET’s own CLR has been around for more than two decades now and has become the foundation for its open source reinvention, while supporting many different languages from a managed C++ implementation to the stalwart C# and Visual Basic and the functional F#. So, it wasn’t hard to provide tools for .NET’s Roslyn compiler to target the WebAssembly byte code rather than the .NET CLR’s.

Blazor WebAssembly tools in Visual Studio

The initial Blazor experiment built on the ASP.NET Core tooling to deliver WebAssembly code using familiar development tools and techniques. Now Blazor and WebAssembly are supported targets for C# development in Visual Studio. If you have a recent version of Visual Studio 2019 installed, start by creating a new project, and then choose to build a Blazor WebAssembly app. This will set up the scaffolding for a Blazor application, with an optional ASP.NET Core host, using either .NET Core 3.1 or .NET 5.0. I’d recommend .NET Core 5.0 for new development, but if you want long-term support you may prefer to choose the .NET Core 3.1 option.

Blazor WebAssembly apps can be delivered as Progressive Web Apps (PWAs) or used as front ends for ASP.NET Core applications. This last option is attractive, especially if you’ve used technologies like Silverlight in the past, as it gives you a set of rich user interfaces for a web application. Unlike Silverlight or Flash, Blazor doesn’t require risky browser plug-ins; everything is managed by the browser and its JavaScript engine (including security and application isolation).

The Visual Studio scaffolding is enough to get you started, providing a WebAssembly host for your code. You can then add controls as needed, using either the standard WinUI controls or working with third-party tools. Popular control vendors such as Infragistics have Blazor implementations of familiar controls with versions for both WebAssembly and server-side Blazor. Third-party controls like these let you build much more complex UIs, similar to those you’d use in a standard desktop application.

Once you’ve built a WebAssembly application you need to get it to your users. The Visual Studio tool gives you some options, but you need to either provide a complete web app for the ASP.NET Core option or use something like the Windows Store to deliver a WebAssembly PWA.

Copyright © 2021 IDG Communications, Inc.