lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.48k stars 725 forks source link

Replace Assembly.Location to AppContext.BaseDirectory #1149

Closed sappho192 closed 2 months ago

sappho192 commented 3 months ago

Pull request type

What is the current behavior?

When you Publish the app which is based on one of the templates (Blank/Compact/Fluent), the app will be crashed since Assembly.GetEntryAssembly()!.Location in App.xaml.cs:23 will always return null. https://github.com/lepoco/wpfui/blob/09eeabd684f2e8f242ceff6deb60e1546d2a7bbf/src/Wpf.Ui.Extension.Template.Blank/App.xaml.cs#L23

This doesn't happen if you "build" the app (both Debug or Release), but when you "publish" it.

This issue also can be notified in build message when you publish the app: IL3000: 'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.

Issue Number: N/A

What is the new behavior?

Other information

Actually the demo app Wpf.Ui.Demo.Mvvm already solved this issue like below, so this can be also applied to the template projects. https://github.com/lepoco/wpfui/blob/09eeabd684f2e8f242ceff6deb60e1546d2a7bbf/src/Wpf.Ui.Demo.Mvvm/App.xaml.cs#L30

References: