[release/10.0] Guard EF file generation against design-time builds to fix AOT build fork bomb - #38386
Merged
Merged
Conversation
…fork bomb (#38087) Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
AndriySvyryd
June 8, 2026 20:58
View session
AndriySvyryd
marked this pull request as ready for review
June 8, 2026 21:06
There was a problem hiding this comment.
Pull request overview
This PR fixes an out-of-control process spawning scenario (“fork bomb”) caused by EF Core build-time code generation running during Visual Studio design-time builds. It updates the Microsoft.EntityFrameworkCore.Tasks MSBuild integration to skip generation targets when $(DesignTimeBuild) is active, ensuring generation only occurs during real builds/publishes.
Changes:
- Guard
_EFGenerateFilesAfterBuildto skip execution during design-time builds. - Guard
_EFGenerateFilesBeforePublishto skip execution during design-time builds.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
artl93
approved these changes
Jun 9, 2026
cincuranet
approved these changes
Jun 9, 2026
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.
Fixes #38087
Description
The
Microsoft.EntityFrameworkCore.Taskspackage wires EF compiled-model / precompiled-query generation into the build via the_EFGenerateFilesAfterBuildtarget, which is registered in$(TargetsTriggeredByCompilation)and therefore runs afterCoreCompile.CoreCompilealso runs during Visual Studio design-time builds — the lightweight builds VS/IntelliSense fire continuously while a project is open. Each time the generation target ran it spawned a full, separate out-of-process MSBuild (which in turn invokes the EF design-time generation, loading the runtime and the user assembly). Because design-time builds fire repeatedly and rapidly, these heavyweight spawned builds piled up and consumed all available memory — effectively a fork bomb. Merely opening the project in Visual Studio was enough to trigger it.The fix adds a
'$(DesignTimeBuild)'!='True'condition to the_EFGenerateFilesAfterBuildand_EFGenerateFilesBeforePublishtargets so that file generation is skipped during design-time builds and only runs during real builds/publishes, where it belongs. This mirrors the existing pattern already used by the EF NetTopologySuite and HierarchyId targets.Customer impact
Customers who enable EF's build-time code generation together with Native AOT (the documented combination of
EFOptimizeContextandPublishAot/EFScaffoldModelStage/EFPrecompileQueriesStage) have their machine's RAM exhausted as soon as the project is opened in Visual Studio or built, making the feature unusable and the IDE unresponsive. There is no practical workaround other than disabling Native AOT, which defeats the purpose of the feature. Example project settings that trigger it:How found
User reported on 10.0.5. The issue has 6 upvotes, indicating multiple affected users.
Regression
Not a regression.
Testing
The
Microsoft.EntityFrameworkCore.Tasksbuild/publish MSBuild integration has no automated test coverage, as it requires real out-of-process MSBuild orchestration including VS-style design-time builds that the test suite does not exercise. Validation was done with a standalone MSBuild repro harness that imports the real targets file and models the SDK compile flow (CoreCompile→$(TargetsTriggeredByCompilation)): with the unguarded targets a design-time build triggers generation (reproducing the bug), while with the guarded targets a design-time build triggers no generation (no spawn, clean exit) and a normal build still generates exactly once and terminates.Risk
Very low. The change is a two-line MSBuild condition addition to a
.targetsfile that only narrows when generation runs (it never runs during design-time builds, where it should never have run). Normal build and publish generation behavior is unchanged.