maui
maui copied to clipboard
BlazorWebView: Use AppContext.BaseDirectory instead of Environment.CurrentDirectory
This is a follow up to https://github.com/dotnet/maui/pull/21505/files/2d4a1bdabf24a22b8df1e32d4535ebc89f6f7308#r1557824040
In BlazorWebView in WPF and WinForms code, we're using Environment.CurrentDirectory as the app root directory in the case when the location of the entry assembly is not known. This is the case when the app is published as a single file. We should use AppContext.BaseDirectory instead.
- https://github.com/dotnet/maui/blob/b183cae2982f7c318f796d202f5c811d4da0edd8/src/BlazorWebView/src/WindowsForms/BlazorWebView.cs#L180
- https://github.com/dotnet/maui/blob/b183cae2982f7c318f796d202f5c811d4da0edd8/src/BlazorWebView/src/Wpf/BlazorWebView.cs#L265
Assign it to me
To repro the original problem:
- Build a WinForms or WPF app using BlazorWebView
- Publish the app as a single EXE
- Run the app from a different folder. That is, say the app is in
c:\myapp\cool_app.exe, then in a command prompt navigate toc:\other_folderand runc:\myapp\cool_app.exe
The original bug was caused by the 'current directory' to be different from where the app is, and due to the app being a single EXE, it couldn't find its own location to locate static assets, so content such as CSS wouldn't load. With the fix in #21797, the app can always locate its files (because the new API works even in single EXE apps), so all the app's content can be found.