BlazorWebView for WPF not debuggable when blazor code is in a different project
See original GitHub issueDescription
I am unable to run/debug WPF application from Visual Studio when hosting a blazor application from another project because index.html does not exist in the output folder. I want to re-use the blazor project from my web application.
WPF’s BlazorWebView
uses PhysicalFileProvider
to the folder of the file pointed to by the value of HostPage
property. But that file is in another project and is not copied to the WPF project’s output folder. If provide path to that file then the generated isolated css file will not be loaded. It should either be customizable and/or a CompositeFileProvider
that uses all paths from the blazor project’s static web assets xml file should be configured if that file exists.
Steps to Reproduce
- Extract the attached zip file
- Open the solution is Visual Studio
- Press F5 to run it
Expected Behavior
The application runs and displays my web page as it would in web browser when the blazor project is run.
Actual Behavior
DirectoryNotFoundException
is thrown pointing to BlazorWpf1\BlazorWpf1\bin\Debug\net6.0-windows\wwwroot\
Basic Information
- Version with issue:
6.0.0-preview.4.21253.5
- Last known good version:
none
- IDE: Visual Studio 2019
- Platform Target Frameworks:
net6.0-windows
- Nuget Packages:
- Microsoft.AspNetCore.Components.WebView.Wpf (version 6.0.0-preview.4.21253.5)
- Affected Devices:
Reproduction Link
Workaround
From the source of WPF WebView, I could not figure out any.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (2 by maintainers)
Hi, I know this is an older issue now, but I got the repro project working on my machine by doing the following:
<Project Sdk="Microsoft.NET.Sdk.Razor">
The reason that (2) is needed is that the logic for making static web assets such as CSS/HTML/JS available is all part of the Razor SDK. By referencing the SDK, that brings in the MSBuild targets that place files in the correct location in order to be loaded by the system.
If you want a totally custom way of providing static assets, we recently added that feature in this PR: https://github.com/dotnet/maui/pull/3191
2 days ago 😁 https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebView.Wpf/6.0.101-preview.11.2349