Background:
I'm writing an application that in some cases will have an Blazor UI. Due to this I want to deliver the Blazor UI part as a plug-in. I already have a few plug-ins that are non UI and that works just fine. Since I'm not an expert when it comes to Blazor the question is probably fairly trivial for all of you.
Anyway, consider the "out of the box" Blazor demo application from VS. It has the counter and the weather. It works nicely.
What if I would like to compile the demo program as an assembly instead of the default Console application and then have another Console application starting it?
In my attempts to make this work I've realized that the secondary console application needs to have its project defined as "Project Sdk="Microsoft.NET.Sdk.Web"" (and not just .NET.Sdk) in order for something to work at all.
But getting the Blazor application to look like it should just does not work for me. My guess is that the webroot is not found (see this this image hopefully shows)
My question is:
What do I need to do to make the "secondary console" application execute my Blazor application (now compiled as an assembly) and make it look and behave just as it normally would do if it was started directly?
Basically what I'm asking for, how can I make the standard startup work from another console?
If I run the regular Blazor app the code below works just fine.
public class MyProgram
{
public static void Main(string[] args)
{
new OurTestBlazorApp().Start();
}
}
public class OurTestBlazorApp
{
public void Start()
{
var builder = WebApplication.CreateBuilder();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
}
}
However if I create a secondary pure console application, edit the project file to add the Web to the Sdk type
<Project Sdk="Microsoft.NET.Sdk.Web">
and run the code
Console.WriteLine("Hello, World!");
new OurTestBlazorApp().Start();
it looks like this image
Any help that can get me out of my misery would be greatly appreciated.
King regards Magnus