Search code examples
c#.netasp.net-coreblazorblazor-webassembly

Can't find the "ASP.NET Core Hosted" checkbox when creating a Blazor project


I'm trying to create a new Blazor WebAssembly application with a backend API server. However, while creating the project in Visual Studio 2022, I can't find the checkbox for "ASP.NET Core Hosted" that was present in previous versions.

According to Microsoft's documentation, in .NET 8 and later:

  • The "ASP.NET Core Hosted" option has been removed from the Blazor WebAssembly template
  • A new unified "Blazor Web App" template has been introduced (which is the one I probably will be using)
  • This new template is meant to replace both Blazor Server and hosted Blazor WebAssembly scenarios

How do I create this type of application structure using the new template system ?

I'm using Visual Studio 2022 and my target framework will be .NET 9.


Solution

  • Visual studio generate 3 projects in the orignal ASP.NET Core Hosted Blazor WebAssembly template

    • ClientProject - this is a Blazor-WASM application
    • ServerProject - this is a .NET CORE application
    • SharedClassProject - this is a class library that holds shared objects between client and server

    And the project reference between them should be like below:

    enter image description here

    If you want to keep the same project structure, you need manually create three project step by step and also need add/modify some configurations which are too complex and easily make mistake. You could refer to this github repo for how to build an ASP.NET Core hosted Blazor WebAssembly app with .NET 8.

    In conclusion, I also agree with @MrC aka Shaun Curtis, suggest you create Blazor Web App with WebAssembly Interactive render mode and Global Interactivity location.