Fix NativeAOT publish: rebuild RID-specific assembly with generated sources#38322
Open
Copilot wants to merge 11 commits into
Open
Fix NativeAOT publish: rebuild RID-specific assembly with generated sources#38322Copilot wants to merge 11 commits into
Copilot wants to merge 11 commits into
Conversation
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…riage md Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…for PublishAot Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
… on PublishAot Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
AndriySvyryd
May 28, 2026 04:50
View session
AndriySvyryd
approved these changes
May 28, 2026
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a NativeAOT publish failure where ILC consumes a stale RID-specific intermediate assembly that was compiled before EF’s generated sources (compiled model / precompiled queries interceptors) were produced, leading to a runtime failure (“Model building is not supported when publishing with NativeAOT”).
Changes:
- Refactors
_EFGenerateFilesto centralize inner-build property computation and ensure the generation build runs in a reflection-friendly configuration (RID cleared,SelfContained=false,PublishAot=false). - Adds an additional post-generation inner
Buildthat restoresPublishAot/RID-related properties to refresh the RID-specific intermediate assembly before ILC runs. - Updates transitive props to include
Microsoft.EntityFrameworkCore.GeneratedInterceptorsinInterceptorsNamespacesso generated interceptor sources compile without consumer opt-in.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/EFCore.Tasks/buildTransitive/Microsoft.EntityFrameworkCore.Tasks.targets | Reworks the inner-build flow to generate sources using a non-RID, non-AOT build and then rebuild the RID-specific assembly after generation; removes the prior CallTarget Build inside OptimizeDbContext. |
| src/EFCore.Tasks/buildTransitive/Microsoft.EntityFrameworkCore.Tasks.props | Enables the generated interceptors namespace by default via InterceptorsNamespaces for transitive consumption. |
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Comment on lines
+65
to
+67
| <!-- Inner builds disable AOT; for AOT publish they also clear RID/SelfContained to use reflection-friendly output. --> | ||
| <_EFInnerBuildProperties>Configuration=$(Configuration);Platform=$(Platform);PublishAot=false;_EFGenerationStage=$(_EFGenerationStage)</_EFInnerBuildProperties> | ||
| <_EFInnerBuildProperties Condition="'$(PublishAot)'=='true' Or '$(_EFPublishAOT)'=='true'">$(_EFInnerBuildProperties);RuntimeIdentifier=;SelfContained=false</_EFInnerBuildProperties> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
dotnet publish /p:PublishAot=true(with or without-r <RID>, and regardless ofEFScaffoldModelStage/EFPrecompileQueriesStage) failed at runtime withModel building is not supported when publishing with NativeAOT. The compiled model and precompiled queries were generated correctly, but ILC consumed the stale RID-specific intermediate assembly produced by the outerCoreCompilebefore generation ran.Targets (
Microsoft.EntityFrameworkCore.Tasks.targets)_EFGenerateFilesto share a single_EFInnerBuildPropertiesacross inner invocations (PublishAot=false, propagates_EFGenerationStage).PublishAot-gated behavior for reflection-friendly inner generation:RuntimeIdentifier=;SelfContained=falseand the first innerBuildnow run only whenPublishAot/_EFPublishAOTis true.OptimizeDbContextrunning with_EFInnerBuildProperties.Build(<CallTarget Targets="Build" />) so the current invocation output (including RID-specific output) is rebuilt with generated sources before publish/ILC consumption.<CallTarget Targets="Build" />fromOptimizeDbContext.Flow
For AOT publish:
For non-AOT publish (including RID publish), the first reflection-only inner
Buildis skipped, and generation/rebuild runs without forcing RID clearing.