Blazor WASM in a single project?

276 Views Asked by At

I noticed with .NET8, whenever you create a new Blazor project, it always generates two projects instead (a "main" and a ".Client" project), no matter what combination of options you choose. Is there a way to create ONLY one project like it was in .NET6?

And also, what's the purpose of having it split into two projects?

3

There are 3 best solutions below

3
LoneSpawn On BEST ANSWER

Use the "Blazor WebAssembly Standalone App" template in Visual Studio to create a single project Blazor WASM app. "Blazor Web App" is the Blazor template that creates 2 projects, server and client, as you have found.

0
Adam Vincent On

The 2 projects one is the "ASP NET Hosted" option I believe. The Shared project being the ASP NET back end, which will serve the Blazor WASM front end to the end user.

The templates change and have many options, these options might not be immediately apparent or described well enough through the Visual Studio "New Project" interface.

I find using dotnet new --help from the console helps me find what I am looking for.

For instance, asking for help on a specific template will list the many options in terms of flags. So if I want individual authentication, a single project style template, and I don't want to use top level statements in my Program.cs I can enter the command:

dotnet new blazorwasm --help

After a quick read I can see I need the following options:

dotnet new blazorwasm --hosted false --auth individual --use-program-main true --name testapp

Note: at the time of writing, the --hosted option is default to false, so this is redundant for information purposes.

0
Said Amir On

This isn't related to having the blazor wasm selfhosted on the api anymore ... its a new way of building your app... this is only explicit for .net8

The app is now using different rendering modes so you can choose between different modes per Page/Component ... instead of having to choose between wasm and server for the whole project.

They added also another rendering Mode Server Side Rendering (Similar to Razor Pages).

The Client project represent WASM components and the Main represents Server Side rendering or Interactive Server Side (Old blazor Server).

https://www.youtube.com/watch?v=YwZdtLEtROA