Let's develop Blazor apps on Linux
Published Jun 11 2019 09:53 PM 26.4K Views
Microsoft

Blazor is one of fantastic technologies I think.

It will be shipped a part of .NET Core 3.0.

 

It can build client side web apps using C#, however it run on web standard like HTML, CSS, JavaScript, WebAssembly and more. I remembered Silverlight that has similar development experience, I liked it, but Blazor is different that is using 100% open web standard technologies.

 

There are two different models:

  1. Server-side Blazor
    This runs on server-side through SignalR.
  2. Client-side Blazor
    This runs on browser using WebAssembly.

However, you can create apps on same programming model.

Of course, it is .NET Core, so you can create Blazor apps on Linux too.

 

Create a Hello world app on Linux

I have an Ubuntu VM on Azure, and I have been using the environments using Visual Studio Code Remote Development feature. It's really cool!!

 

NOTE: .NET Core 3.0 is still preview. Please install .NET Core 3.0 from here.

 

Let's create a project using following command:

$ dotnet new blazor -o BlazorHelloWorld

The command is to create a server-side blazor app.(In document, dotnet new blazor is a client-side blazor project template. However, in my case, it was created a server-side blazor project.)

And please type dotnet run!!

$ dotnet run

You can look the app from https://localhost:5001. When using Visual Studio Code Remote Development, please add FORWARDED PORTS setting, like following:

コメント 2019-06-12 114359.jpg

After access the address, you can see an app like below:

コメント 2019-06-12 114720.jpg

Looking around

When displaying the app, there are few messages on Debugging tool of Web Browser.(I'm using Edge preview.)

コメント 2019-06-12 115125.jpg

It means the app is connecting to a server using WebSocket of SignalR.

And you will find WebSocket connection on the Network tab that name is _blazor?id=xxxxxx. If you selected it, then you would see many binary messages.

コメント 2019-06-12 120120.jpg

Server-side blazor is running on server side, it means the app manages many information for client like DOM tree, state, etc...

Web browser is just to render and communicate to the server.

 

Deploy to azure

You can deploy the app to Azure Web app on Linux(Of course, you can also deploy Azure Web app on Windows.)

Let's create Web app on Linux with Free plan.

コメント 2019-06-12 123046.jpg

And create a package to deploy the Web app using following command:

$ dotnet publish -c Release --self-contained -r linux-x64
$ cd bin/Release/netcoreapp3.0/linux-x64/publish
$ zip -r app.zip .

After creating a zip package, you can deploy the app to azure using Azure CLI!

$ az webapp deployment source config-zip --resource-group <your resource group name> --name <your web app name>--src app.zip

After that, set "dotnet YourProjectName.dll" to <your web app> -> Configuration -> General settings -> Startup Command.

コメント 2019-06-12 130009.jpg

Congrats!! The Blazor app works on App Service on Linux. But unfortunately, WebSocket(SignalR) is unavairable. There are many http requests.

blazorlinux.gif

If you want to use WebSocket, an easy way is to use Azure Web app on Windows.

 

Wrap up

Blazor is really powerful technology to build Single Page Applications! It will be released a part of .NET Core 3.0 at Sep 2019.

It works on web standard technologies(not plugin). 

Client-side blazor is not in this article, but you can try it and deploy to everywhere.

 

The following link is official documentation of Blazor. If you feel Blazor is interesting, then please read it.

https://docs.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-3.0

 

Version history
Last update:
‎Jun 11 2019 09:53 PM
Updated by: