-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create a self-contained native executable. #281
Comments
I recommend to not use the templates (they are out of date), but take a look at the getting started section of You could also clone the repository and check out the examples. Let me know if you encounter any issues. |
Which versions of Avalonia and/or FuncUI? (there have been a lot of changes that effect trimming in Avalonia 11, including some to resolve styles at build time to avoid the linker trimming them) FWIW, I've had single file apps working with FuncUI in both .NET 6 and 7, though I currently have |
Thanks Numpsy, with : < TrimMode > partial< / TrimMode > it worked fine !!! |
I believe that the issue with the themes/styles is that the trimmer can't understand things that are only referenced dynamically (e.g. via xaml that's loaded at runtime), so it decides they're unused and removes them. (Setting TrimMode is one way of avoiding that, as it means that only assemblies that are explicitly marked as trimmable will be trimmed). Avalonia 11 has been getting some changes to help with this by resolving the styles at compile time and using compiled xaml to create strong references to everyting, so that they won't be trimmed. However, I don't know if that's all done yet, or of there might yet be anything in FuncUI that needs tweaking or annotating as well. Another approach to the problem is to leave the TrimMode set to Full and use the per assembly settings documented at https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-7-0#root-assemblies to keep specific ones - The Avalonia web assembly control catalog sample at https://github.com/AvaloniaUI/Avalonia/tree/master/samples/ControlCatalog.Browser does that with a Roots.xml file |
A bit more info on this, as i'm looking at it again, and can use the control catalog sample as an example now: Say that you have something like this: Where it loads the styles dynamically. However, because the local styles are only referenced by a string, and the linker can't understand that, the style data can be removed, so you get the ops exception:
However, as of Avalona 11 P5, it now has the ability to resolve styles specified in xaml at compile time and inject hard references to those in the binary, so that they won't be trimmed. So if you have xaml like this: <Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Avalonia.FuncUI.ControlCatalog.App">
<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.FuncUI.ControlCatalog/Styles/TabControl.xaml"/>
</Application.Styles>
</Application> and change the startup code to this type App() =
inherit Application()
override this.Initialize() =
Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this) The the styles get retained. |
On the subject of the control catalog, if I build it as .NET 7 with full trimming then I get this:
though that sounds like Elmish trying to do reflection based log formatting on things that have been trimmed, rather than a FuncUI specific thing (something else to watch out for with trimming though) |
Closing this as the question is not related to FuncUI |
I witched to gentoo-linux as development environment:
I tried in the project file
dotnet publish
& run the application returns:
The text was updated successfully, but these errors were encountered: