.NET7.0+ AOT supported by xljiulang · Pull Request #1710 · reactiveui/refit
What kind of change does this PR introduce?
This is an implementation complement to #1389, which enables Generated.g codes to be preserved during trimming, thereby supporting AOT publish of .NET 7.0 or later versions.This implementation has been used in the WebApiClient project and is valid for .NET versions 5.0 to 9.0 and is safe.
What is the current behavior?
<TrimMode>full</TrimMode> is the default behavior of .NET8. Once <PublishAot>true</PublishAot> is turned on, all the code currently generated in Generated.g will be trimmed, causing AOT publishing to fail.
What is the new behavior?
Cleverly use ModuleInitializerAttribute in combination with DynamicDependencyAttribute to prevent the code of Generated.g from being trimmed.
What might this PR break?
This PR is non-destructive, but requires the target project to be .NET 5 or above to take effect.
Please check if the PR fulfills these requirements
- Tests for the changes have been added (for bug fixes / features)
- Docs have been added / updated (for bug fixes / features)
Other information: