Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 inGenerated.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
Other information: