I use Avalonia on Gentoo-Linux to create an F# GUI. But want an exe

How do I create a “self-contained” executable with F# ?
I tried in the project file:

<SelfContained>true</SelfContained>
	<PublishSingleFile>True</PublishSingleFile>
	<PublishTrimmed>true</PublishTrimmed>
	<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

But when i place or the dll or the exe to another place it fails.
So for some reason or not everything is “in it”.
Note there are 620 dll’s in my application folder.
But i want just one by ,preference native executable, if not possible interpreted dll, which contains all the dependencies.

The error i get with run after publish is:

/NewApp 
Unhandled exception. Avalonia.Markup.Xaml.XamlLoadException: No precompiled XAML found for avares://Avalonia.Themes.Fluent/Accents/AccentColors.xaml (baseUri: ), make sure to specify x:Class and include your XAML file as AvaloniaResource
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Uri, Uri ) in /_/src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs:line 74
   at Avalonia.Markup.Xaml.Styling.StyleInclude.get_Loaded() in /_/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs:line 54
   at Avalonia.Markup.Xaml.Styling.StyleInclude.Avalonia.Controls.IResourceProvider.AddOwner(IResourceHost) in /_/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs:line 98
   at Avalonia.Styling.Styles.Avalonia.Controls.IResourceProvider.AddOwner(IResourceHost) in /_/src/Avalonia.Styling/Styling/Styles.cs:line 240
   at Avalonia.Styling.Styles.Avalonia.Controls.IResourceProvider.AddOwner(IResourceHost) in /_/src/Avalonia.Styling/Styling/Styles.cs:line 240
   at Avalonia.Themes.Fluent.FluentTheme.Avalonia.Controls.IResourceProvider.AddOwner(IResourceHost) in /_/src/Avalonia.Themes.Fluent/FluentTheme.cs:line 142
   at Avalonia.Styling.Styles.<OnCollectionChanged>g__Add|52_1(IList) in /_/src/Avalonia.Styling/Styling/Styles.cs:line 289
   at Avalonia.Styling.Styles.OnCollectionChanged(Object, NotifyCollectionChangedEventArgs) in /_/src/Avalonia.Styling/Styling/Styles.cs:line 318
   at Avalonia.Collections.AvaloniaList`1.NotifyAdd(T, Int32) in /_/src/Avalonia.Base/Collections/AvaloniaList.cs:line 681
   at Avalonia.Collections.AvaloniaList`1.Add(T) in /_/src/Avalonia.Base/Collections/AvaloniaList.cs:line 205
   at Avalonia.Styling.Styles.Add(IStyle) in /_/src/Avalonia.Styling/Styling/Styles.cs:line 201
   at NewApp.App.Initialize() in /home/x/avalonia/NewApp/Program.fs:line 25
   at Avalonia.Controls.AppBuilderBase`1.Setup() in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 310
   at Avalonia.Controls.AppBuilderBase`1.SetupWithLifetime(IApplicationLifetime) in /_/src/Avalonia.Controls/AppBuilderBase.cs:line 179
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T, String[], ShutdownMode ) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 208
   at NewApp.Program.main(String[]) in /home/x/avalonia/NewApp/Program.fs:line 37
Aborted
<PropertyGroup>
    <PublishReadyToRun>true</PublishReadyToRun>
    <SelfContained>true</SelfContained>
	<PublishSingleFile>True</PublishSingleFile>
	<PublishTrimmed>true</PublishTrimmed>
 <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    <OutputType>Exe</OutputType>
    <TrimMode>partial</TrimMode>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>

It worked with this. The important was the trimmode.
[Altough i don’t know why]

2 Likes