Figuring out the project structure
Visual Studio will generate two projects: Blazor App
, which is the server project, and BlazorWebApp.Client
, which is where we put our WebAssembly components.
Now, it’s time to look at the different files and how they may differ in different projects. Take a look at the code in the two projects we just created (in the Creating our first Blazor app section) while we go through them.
Program.cs (BlazorWebApp project)
Program.cs
is the first class that gets called. So, let’s start looking at that one.
The Program.cs
file looks like this:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("...