SteveSandersonMS / WebWindow

.NET Core library to open native OS windows containing web UI on Windows, Mac, and Linux. Experimental.
Apache License 2.0
1.98k stars 215 forks source link

Does not work with p:PublishSingleFile #14

Closed seriouz closed 4 years ago

seriouz commented 4 years ago

First of all: This is a great tool, thanks! But when i am building the app like this dotnet publish -c Release --framework netcoreapp3.0 --runtime win-x64 /p:PublishSingleFile=true the index.html file cannot be reached. I don't know if this is a problem with the bundler or in the application when the file is being resolved.

distantcam commented 4 years ago

The bundler won't include the wwwroot folder, and even if it did, the WebWindow won't know to load the files from somewhere other than the filesystem.

I created a project that embeds the wwwroot folder into the assembly and code to let the WebWindow load files from the assembly when the app:// schema is used. https://github.com/distantcam/WebWindow.ViewModelExample

SteveSandersonMS commented 4 years ago

Thanks for answering, @distantcam!

sondreb commented 4 years ago

Here is the solution you can use to find the wwwroot folder when you publish as a single file:

string directory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var path = System.IO.Path.Combine(directory, "wwwroot", "index.html");
window.NavigateToLocalFile(path);

Only tested on Windows, but it is likely this will work on all platforms. Depends perhaps how it is started, and you could change the code to get assembly to find one of your custom classes instead of using the executing assembly.

Example path where single publish file is extracted:

C:\Users\USER\AppData\Local\Temp\.net\YourAppName\pnlm53kp.ran\