Skip to content

Commit 5c96234

Browse files
[release/10.0] Guard EF file generation during commandline builds to fix AOT build fork bomb (#38403)
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
1 parent 525a9a0 commit 5c96234

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/EFCore.Design/Design/Internal/DbContextOperations.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ private IReadOnlyList<string> PrecompileQueries(
303303

304304
try
305305
{
306-
workspace = MSBuildWorkspace.Create();
306+
// Set _EFGenerationStage to a non-empty value so that the design-time build performed by
307+
// OpenProjectAsync below doesn't re-trigger the EF file generation targets. Otherwise the
308+
// generation targets would invoke this operation again, resulting in a fork bomb.
309+
workspace = MSBuildWorkspace.Create(new Dictionary<string, string> { ["_EFGenerationStage"] = "build" });
307310
workspace.LoadMetadataForReferencedProjects = true;
308311
#pragma warning disable CS0612 // Obsolete
309312
#pragma warning disable CS0618 // Obsolete

src/EFCore.Tasks/buildTransitive/Microsoft.EntityFrameworkCore.Tasks.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ For Publish:
166166
This target has the same Inputs and Outputs as CoreCompile to run only if CoreCompile isn't going to be skipped -->
167167
<Target Name="_EFPrepareForCompile"
168168
DependsOnTargets="_EFProcessGeneratedFiles"
169-
Condition="'$(_EFGenerationStage)'==''"
169+
Condition="'$(_EFGenerationStage)'=='' And '$(DesignTimeBuild)' != 'True'"
170170
Inputs="$(MSBuildAllProjects);
171171
@(Compile);
172172
@(_CoreCompileResourceInputs);

0 commit comments

Comments
 (0)