Purpose of Microsoft.AspNetCore.Components.WebAssembly.Server package
Asked Answered
D

1

9

I'm using ASP.NET Core 6. I'm trying to add a blazor project to an existing monorepo that includes a web API server project. I ran dotnet new blazorwasm --hosted, and the generated server project includes this package:

<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.4" />

What is its purpose - do I need it? The docs say:

Provides types for hosting the Blazor development server locally. Intended for framework use only, not supported for use in application code.

That's confusing - why is it included in the template? And it's not hidden behind a Development environment build step.

Also, how does it differ to the Microsoft.AspNetCore.Components.WebAssembly.DevServer package?

(The generated client blazor project also references Microsoft.AspNetCore.Components.WebAssembly and Microsoft.AspNetCore.Components.WebAssembly.DevServer. I'm curious how all these are related.)

Devol answered 25/4, 2022 at 4:51 Comment(1)
I understand your confusion in the document. I could help you clarify it. The document mentioned that the .net core framework will use while compiling or executing the code or in the background. So yes, we need to add a reference to it in the project. It is not recommended to use this class in your own code. As it is not made for that purpose, you will not find its usage document.Stinnett
S
7

If you comment out the package and then rebuild the Server project you'll get the following errors in Program:

enter image description here

They contain the middleware that maps the correct project files and infrastructure in the hosted server project. An example is mapping the client project wwwroot directory.

Sian answered 25/4, 2022 at 7:27 Comment(3)
Thanks. The doc I quoted above was confusing. But your answer shows this package is necessary, even in production.Devol
Basically Microsoft.AspNetCore.Components.WebAssembly.DevServer is an development server executable (not a library) which is based on the library Microsoft.AspNetCore.Components.WebAssembly.Server (see here )Frost
Please note - the DevServer package reference will break .NET WebAPI projects - the Server reference is the only one needed (.NET 8, Blazor WASM with .NET Core hosted)Pathway

© 2022 - 2024 — McMap. All rights reserved.