Skip to content

Conversation

@mjcheetham
Copy link
Contributor

@mjcheetham mjcheetham commented Sep 20, 2023

Depends on: #1417 and #1418

Now that we no longer have to target .NET Framework on Windows, and we are using the latest .NET (.NET 8) and CoreCLR, we can take advantage of the mature and stable assembly trimming logic in the SDK.

This will allow us to reduce the number and sizes of binaries that we produce and ship. In addition we enable single-file publishing on all platforms that links all CIL code in to the same entry executable. Native dependencies remain separate files, such as the MSAL runtime, and Avalonia graphics library dependencies.

In order to enable trimming we had to:

  • Use source generation in System.Text.Json
  • Enable compiled bindings in Avalonia components

** TODO: size comparisons **

Fixes: #113

@mjcheetham mjcheetham force-pushed the publish-trim branch 6 times, most recently from 4fa39ba to a958838 Compare September 22, 2023 19:05
@mjcheetham mjcheetham force-pushed the publish-trim branch 2 times, most recently from dd98457 to 07416b1 Compare November 10, 2025 17:00
Annotate any OS or platform specific code with the new
(Un)SupportedOSPlatform(Guard) attributes and update various platform
util methods to use the OperatingSystem.Is<platform> methods.

This will help ensure we're not missing any OS checks in the future.

For test projects we ignore these warnings since we're using skipping
Xunit tests that are not applicable for the current platform already,
making these warnings just noise.
Update Avalonia dependencies to 11.3.8.
Enable compression of assemblies in the single-file distribution of GCM.
This helps reduce the overall size on disk of GCM, which is important on
Windows as we are bundled with Git for Windows, and we don't want to
bloat their distribution.

We only enable this compression on Windows. Mac and Linux remain
uncompressed.
Replace single-file trimming publishing with full AOT publishing.
This should also result in an increased execution performance as we
no longer need to JIT any code at runtime.
.NET 8 only supports AOT compilation on a subset of .NET runtimes,
namely:

- win-x64
- win-arm64
- osx-x64
- osx-arm64
- linux-x64
- linux-arm64

This means we need to do something else of our win-x86 and linux-arm
(32-bit) targets.

For these two, let's use the combo of SingleFile+Trimmed+ReadyToRun
publishing options instead to keep both file sizes down, and reduce
runtime performance hits from JIT.

.NET 9 and later support AOT for win-x86 and linux-arm (32-bit) targets,
but since we only prefer to target LTS releases of .NET, we'll have to
wait for .NET 10 (the next LTS release) to do AOT on _all_ our
platforms.

Given that .NET 10 GA is just around the corner, this shouldn't be too
long to wait.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate from .NET Framework on Windows

1 participant