Skip to content

Conversation

@xljiulang
Copy link
Contributor

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:

@codecov
Copy link

codecov bot commented Jun 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.62%. Comparing base (6ebeda5) to head (5784f2d).
Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1710      +/-   ##
==========================================
- Coverage   87.73%   86.62%   -1.11%     
==========================================
  Files          33       34       +1     
  Lines        2348     2064     -284     
  Branches      294      296       +2     
==========================================
- Hits         2060     1788     -272     
+ Misses        208      199       -9     
+ Partials       80       77       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants