Figuring out the project structure
Now it's time to take a 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
Program.cs
is the first class that gets called. It also differs between Blazor Server and Blazor WebAssembly.
WebAssembly Program.cs
In the WebAssembly.Client
project, there is a file called Program.cs
and it looks like this:
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();
Program.cs
uses top-level statements without any classes or methods.
By using top-level statements, C# understands that this is the entry point of the...