When I create an ASP.NET Core hosted Blazor app from the .NET template I get something like this:
- WebHost project (Microsoft.NET.Sdk.Web, Exe output type)
- BlazorApp project (Microsoft.NET.Sdk.BlazorWebAssembly, Exe output type)
I can easily run dotnet publish
on the WebHost project and will get an executable that hosts all the content of the Blazor web app.
So if I want to add a server configuration UI e.g. using WPF, I eventually end up with something like this. (the WebHost project is now a library and used/referenced by ServerUI)
- ServerUI project
- Uses
Microsoft.NET.Sdk
withUseWPF
set totrue
OutputType
is set toWinExe
- Top level project which es meant to be the entry point for the (server) application
- Contains a graphical user interface to set up the server (e.g. ports, authentication, etc.)
- References WebHost project
- Uses
- WebHost project
- Uses
Microsoft.NET.Sdk.Web
to have access to the ASP.NET Core runtime OutputType
is set toLibrary
- Contains all the code for ASP.NET Core hosting
- References BlazorApp project
- Uses
- BlazorApp project
- Uses
Microsoft.NET.Sdk.BlazorWebAssembly
OutputType
is set toExe
(default)- Contains all the Blazor web app stuff to run in the browser
- Uses
If I now run dotnet publish
on the ServerUI project, I will end up with an executable that shows a user interface and has ASP.NET Core hosting stuff but accessing the Blazor web app will fail, since the wwwroot
folder will not be published that way.
Now there are two ways to fix this issue that I am aware of:
- Either you make the ServerUI also use the
Microsoft.NET.Sdk.Web
- or you explicitly publish either the WebHost or the BlazorApp project into the same folder as the ServerUI project.
That gets me to the question, is it actually possible to use Microsoft.NET.Sdk.Web
for library projects and if so, what are the limitations.
Steps to reproduce
- Clone this repo
- Open a terminal in the checked out folder
- Run
dotnet publish ServerUI -o bin\publish
wwwroot
folder will be missing in thebin\publish
directory- In contrast running
dotnet run --project ServerUI
will nevertheless work as intended, since it does not rely on the publish behavior