Creating a New Blazor Project
Syntax
To create a new Blazor project, use the following command in the terminal:
dotnet new blazorproject -n ProjectName
Here, ProjectName
is the name you want to give your project.
Example
To create a new Blazor project called MyApp
, use the following command:
dotnet new blazorproject -n MyApp
Output
After running the above command, a new folder named MyApp
will be created with the following structure:
MyApp
│ .gitignore
│ MyApp.sln
│
└───MyApp
│ appsettings.Development.json
│ appsettings.json
│ Program.cs
│ Startup.cs
│
├───Data
├───Pages
├───Shared
└───wwwroot
Explanation
MyApp.sln
: The solution file for your project.appsettings.Development.json
andappsettings.json
: JSON files used to configure your application.Program.cs
: The entry point for your application.Startup.cs
: Configures your application's middleware pipeline.Data
: A directory for your application's data models.Pages
: A directory for Razor components representing pages in your application.Shared
: A directory for shared Razor components.wwwroot
: A directory for your application's static files, such as CSS and JavaScript.
Use
You can now start building your Blazor application within the project by adding Razor components to the Pages
or Shared
folders, and using the static files in the wwwroot
folder.
Important Points
- Blazor projects require .NET Core 3.1 or later.
- The
dotnet new blazorproject
command creates a server-side Blazor project by default. - To create a client-side Blazor project, use the
dotnet new blazorwasm
command instead.
Summary
Creating a new Blazor project is simple with the dotnet new blazorproject
command. Once you have created your project, you can start building your application by adding Razor components and using the static files in the wwwroot
folder. Remember that Blazor projects require .NET Core 3.1 or later, and that creating a client-side Blazor project requires the dotnet new blazorwasm
command instead.