In this step, you will create a new Blazor WebAssembly application using the dotnet
command-line interface (CLI).
With Blazor WebAssembly, you build a web application purely running on a web browser. It's a modern single-page application (SPA) framework that runs on WebAssembly. It's a new way to build interactive client-side web UI with .NET.
👉 Image source: Microsoft
Generally speaking, web frontend UI applications rely on JavaScript for user interactions. If you don't know JavaScript, you have to learn it first to build an application. However, if you are a new starter building a web frontend UI application and don't know where to start, this Blazor WebAssembly is a good starting point for you because you only need to know C# and .NET for building both frontend and backend applications.
OK. Let's get started!
-
In the terminal, enter the following commands to setup the workshop folder. Remember that
$CODESPACE_VSCODE_FOLDER
is the root directory of your codespace workspace.cd $CODESPACE_VSCODE_FOLDER mkdir workshop cd workshop
-
Enter the following command to create a new Blazor WebAssembly project.
dotnet new blazorwasm -n MyPortfolio
-
Enter the following commands to create a solution file and add the Blazor WebAssembly project to the solution.
dotnet new sln -n MyPortfolio dotnet sln add MyPortfolio
-
Make sure you're in the
workshop
directory.cd $CODESPACE_VSCODE_FOLDER/workshop
-
Build your Blazor WebAssembly project to make sure everything is working fine.
dotnet restore && dotnet build
-
Run the Blazor WebAssembly project to see the default application.
dotnet watch run --project MyPortfolio
-
You should see the popup message like below. Click the "Open in Browser" button to open the default Blazor WebAssembly application in your browser.
The screenshot above shows the port number of
5033
, but it might be different from yours. -
The default Blazor WebAssembly application is open, and should look like below.
The web application's URL should look like
https://{{your-github-codespace-name}}-5033.app.github.dev
, instead ofhttps://localhost:5033
, where5033
is your port number, which might be different from yours. -
Stop the running application by pressing
Ctrl + C
in the terminal.
Congratulations! You have created a new Blazor WebAssembly application. Let's add some contents by creating a new component in the next step.