Exercise - Create and run a Blazor web app
Let's set up our .NET development environment and create our first Blazor web app.
This module gives you the option to use the .NET CLI, Visual Studio Code, or Visual Studio 2022 for local development. If you're developing with Visual Studio Code, be sure to install the C# Dev Kit extension, which we use in this module.
cloud computing training courses malaysia
This module uses the .NET 8.0 SDK. Ensure that you have .NET 8.0 installed by running the following command in your preferred command terminal:
dotnet --list-sdks
Output similar to the following example appears:
6.0.317 [C:\Program Files\dotnet\sdk]
7.0.401 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]
Ensure that a version that starts with 8 is listed. If none is listed or the command isn't found, install the most recent .NET 8.0 SDK.
ai artificial intelligence training courses malaysia
Create a new Blazor web app with the C# Dev Kit
To create a new Blazor web app project in Visual Studio Code with the C# Dev Kit:
Bring up the Command Palette using Ctrl + Shift + P and then type .NET.
Find and select the .NET: New Project command.
Select Blazor Web App in the dropdown list.
Select the folder where you want to create the new project.
Name the project BlazorApp and press Enter to confirm.
Select Create Project.
View your new Blazor app project in the Explorer.
Optional: Create a new Blazor app with the .NET CLI
To create a Blazor web app project using the .NET SDK from the command-line, use the following command:
dotnet new blazor
Whether you created the Blazor app with Visual Studio Code or the .NET CLI, the generated project contains the following files and pages:
- Program.cs is the entry point for the app that starts the server and where you configure the app services and middleware.
- App.razor is the root component for the app.
- Routes.razor configures the Blazor router.
- The Components/Pages directory contains some example web pages for the app.
- BlazorApp.csproj defines the app project and its dependencies and can be viewed by double-clicking the project node in the Solution Explorer.
- The launchSettings.json file inside the Properties directory defines different profile settings for the local development environment. A port number is automatically assigned at project creation and saved on this file.
Run the app with the integrated debugger
In Visual Studio Code, select Run from the menu.
Select Start Debugging.
Select C# from the Select debugger drop down.
Select C#: BlazorApp [Default Configuration]
This builds and starts the app with debugging enabled. The app should automatically open in your default browser. Your browser might warn you that the site isn't secure; it's safe to proceed.

juniper networks training courses malaysia
Optional: Run the app with the .NET CLI
In the terminal window, copy and paste the following command to run the app and watch for file changes:
.NET CLIdotnet watchThis command builds and starts the app, and then applies any code changes to the running app. The app should automatically open in your default browser. Your browser might warn you that the site doesn't yet have a valid certificate; it's safe to proceed.
You've successfully run your first Blazor app!
Use this Blazor app in the following exercises.
Comments
Post a Comment