Skip to content

Fix scaffolding failure when DbContext/model classes live in a separate referenced project - #3790

Draft
haileymck with Copilot wants to merge 3 commits into
mainfrom
copilot/scaffold-controller-with-separate-dbcontext
Draft

Fix scaffolding failure when DbContext/model classes live in a separate referenced project#3790
haileymck with Copilot wants to merge 3 commits into
mainfrom
copilot/scaffold-controller-with-separate-dbcontext

Conversation

Copilot AI commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Scaffolding CRUD controllers, Razor Pages, Blazor, etc. fails with Invalid --model / Invalid --dataContext when the DbContext and model classes are defined in a separate class library referenced via ProjectReference, instead of in the project passed to --project.

Root cause

  • CodeService.GetAllClassSymbolsAsync() only inspected syntax trees from the main project's own compilation, so any class declared in a referenced project (e.g. a shared data/models library) was invisible to the model/DbContext lookup used by all Validate*Step scaffolding steps.

Fix

  • GetAllClassSymbolsAsync now walks the Roslyn project dependency graph (GetProjectsThatThisProjectTransitivelyDependsOn) to find every project transitively referenced by the main project.
  • Compilations for each referenced project are fetched and their class symbols merged with the main project's, de-duplicated via Distinct.
  • Entry-point resolution (GetEntryPoint) remains scoped to the main project's compilation only, since referenced class libraries have no entry point.
// Before: only classes in the main --project compilation were visible
// After: classes in transitively-referenced projects (e.g. a Data/Models class library)
// are also discoverable for --model and --dataContext resolution
var allClasses = await projectInfo.CodeService.GetAllClassSymbolsAsync();

Copilot AI and others added 2 commits August 5, 2026 21:32
Co-authored-by: haileymck <111816896+haileymck@users.noreply.github.com>
…-point handling

Co-authored-by: haileymck <111816896+haileymck@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix scaffolding issue with DbContext in separate project Fix scaffolding failure when DbContext/model classes live in a separate referenced project Aug 5, 2026
Copilot AI requested a review from haileymck August 5, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scaffolding doesn't work when DbContext is in a separate project

2 participants