Blazor isn't the only way of doing WebAssembly in C#
WebAsembly (abbreviated as Wasm) is a technology that enables the execution of compiled code in browsers. This allows developers to build in-browser apps that can do things that are hard to do with JavaScript, such as 3D games.
WebAssembly is typically associated with low-level programming languages, such as C, C++, and Rust. .NET developers can also build WebAssembly apps in C# by using Blazor.
But what if I told you that Blazor is not the only way of building WebAssembly apps in C#? There is also Wasm implementation available in the Uno Platform. It’s less well-known than Blazor, but it’s just as good.
In certain scenarios, Uno Platform may even be a better choice than Blazor. We will talk about those scenarios later. For now, let’s see how Uno Platform Wasm and Blazor differ from each other.
How Uno Platform Wasm differs from Blazor
As of 2024, there are three different flavors of Blazor:
Blazor WebAssembly, which is an app that is hosted in the browser
Blazor Server, which is an app with no in-browser compiled components, but with rich interactivity between the front-end and the back-end
Blazor Web App, which is a combination of a Blazor WebAssembly app and the host server-side components
We will focus on Blazor WebAssembly, as Blazor Server is a completely different hosting model that is out of the scope of our discussion.
Blazor project structure
If you aren’t familiar with Blazor, here is a typical folder structure for its WebAssembly variation:
As we can see, a Blazor WebAssembly app has the index.html file inside the wwwroot folder. The WebAssembly component is hosted inside a standard HTML page and this is the file that represents this page. Just like any standard HTML file, it can have references to CSS and JavaScript. In fact, Blazor allows you to invoke C# code from JavaScript and vice versa.
Just like almost any other .NET project type, a Blazor project has the Program.cs file. This file acts as the application entry point and contains the application startup code.
In the above example, the majority of the files have the .razor extension. These files combine the standard HTML with compilable C# code. They also use the so-called “Razor syntax” to make the HTML markup interact with the C# logic.
In a nutshell, Blazor WebAssembly is a software development framework that allows developers to build Wasm apps by combining the standard front-end technologies (HTML, JavaScript, and CSS) with C#.
Uno Platform Wasm takes a different approach.
Uno Platform project structure
Unlike Blazor, Uno Platform was not primarily designed to be a web development framework. It is a framework for developing cross-platform UI applications. It allows you to build desktop and mobile applications for different operating systems from the same codebase with minimal usage of OS-specific components.
Here is an example of a project that has support for different types of platforms:
As we can see, Wasm happens to be one of the compilation targets. After all, Wasm is a technology that allows compiled apps to be hosted in the browser, which makes these types of apps not much different from either mobile or desktop apps.
In fact, Wasm apps can be made into the so-called Progressive Web Apps (PWAs), which can be downloaded and installed on the device directly from the web page they are hosted on. More on that later.
If we open the Wasm-specific folder, we will see some files containing icons, layouts, and basic glue code. There is almost no business logic:
By default, most of the business logic will not be tied to any specific platform. It will be shared between all supported platforms. This is what the structure of the platform-independent folder will look like in a newly created project:
Most of the user interface markup will be built inside the platform-independent library too. In an Uno Platform app, the UI markup is either written in C# or we can use a declarative Extensible Application Markup Language (XAML), which is a variation of XML.
Developers who are familiar with building mobile and desktop apps will find it easy to build Wasm apps on the Uno Platform. XAML is used in other frameworks, such as WPF, Xamarin.Forms, and .NET MAUI. While knowing HTML, CSS, and JavaScript may help, it’s not essential for building a Wasm app on the Uno Platform.
Uno Platform Wasm apps examples
If you want to see some interesting examples of Uno Platform Wasm apps available live on the web, here are some of them.
The following app is a Windows calculator deployed on the web. It uses the same code too:
https://calculator.platform.uno/
This app is a web-hosted NuGet package manager from Visual Studio:
This is an app that provides reference material on how to build Uno Platform applications:
Here is a fully interactive Uno Platform playground where you can write UI markup and immediately see what it looks like:
https://playground.platform.uno/
You can find more examples of live Wasm Uno Platform apps on its official GitHub page:
https://github.com/unoplatform/uno
PWA integration
You may have noticed that for some of these live apps, the following icon appears in the address bar of the browser:
This means that the app is a PWA. If you click on this icon, you will be able to install it on your device and use it as any other installed app.
So now we finally reached the important question:
Blazor vs Uno Platform: which one to choose?
The answer to this question won’t be very straightforward. Both platforms are good. Both platforms are constantly being updated. Both platforms have large and helpful online communities.
However, there still may be scenarios where one of the platforms is a better choice than the other. And that is primarily driven by the existing set of skills of the developers on your team. Here is how you can make the decision on which platform to choose:
If web development skills dominate in your team, Blazor would probably be a better choice.
If your team primarily consists of desktop or mobile app developers, then Uno Platform may be a better choice.
Of course, there is nothing that stops a web development team from adopting the Uno Platform or a desktop development team from adopting Blazor. This distinction is purely based on the steepness of the learning curve which will determine how quickly your team is likely to get used to the framework.
Other than this, it would be a matter of preference.