I'm trying to build an application using a Blazor Hybrid Webview, which can be run both from a .NET MAUI application as well as a WPF application. All Pages/Components/Routing etc. are located in a Razor class library (the GUI library). I can't get the wwwroot to the contained in the UI library however.
In both WPF and MAUI the BlazorView hostpage needs to be a static file, wwwroot\index.html, which has to be located inside the running application. I don't want to have to copy things like images and styles all the time. They need to be in the UI library.
I tried all methods of including the folder in the running project, like
<ItemGroup>
<Content Include="..\GUI.Blazor\wwwroot\**" CopyToOutputDirectory="Always"/>
</ItemGroup>
And also by directly using the UIs index.html by creating the BlazorWebview like this
<BlazorWebView HostPage="../GUI.Blazor/wwwroot/index.html">
</BlazorWebView>
But with no success, I keep getting an error saying the folder isn't found, or Blazor simply crashes
It seems impossible.
If you create MAUI app project:
1.Add the Razor SDK,
Microsoft.NET.Sdk.Razorto your project by editing its first line of the CSPROJ project file:2.Add the root Razor component for the app to the project.
3.Add your Razor components to project folders named Pages and Shared.
4.Add your static web assets to a project folder named wwwroot.
5.Add any optional _Imports.razor files to your project.
6.Add a BlazorWebView to a page in your .NET MAUI app, and point it to the root of the Blazor app:
7.Modify the
CreateMauiAppmethod of yourMauiProgramclass to register theBlazorWebViewcontrol for use in your app. To do this, on theIServiceCollectionobject, call theAddMauiBlazorWebViewmethod to add component web view services to the services collection: