Improve dotnet-ef diagnostics#38190
Conversation
…d apps Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/dfcedba0-300c-46da-8051-aa91bb382db6 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/dfcedba0-300c-46da-8051-aa91bb382db6 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
…t, capture output in tests Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/defe39d9-42f3-4eed-98af-03d195b1d3b7 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Improves dotnet-ef project metadata extraction diagnostics by surfacing underlying dotnet build failures (especially restore-related ones) and updating related user-facing messages/tests.
Changes:
- Capture
dotnet buildstderr duringProject.FromFileand report it throughReporter. - Add more specific failure modes (
ProjectFileNotFound,RestoreRequired) and update the generic metadata failure message. - Update
dotnet-eftests to captureReporteroutput and assert that the success path doesn’t emit error-prefixed output.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/dotnet-ef.Tests/ProjectTest.cs | Captures Reporter output during tests and adds coverage for missing project file behavior. |
| src/dotnet-ef/Properties/Resources.resx | Adds/updates resource strings for improved Project.FromFile diagnostics. |
| src/dotnet-ef/Properties/Resources.Designer.cs | Regenerates strongly-typed resource accessors for new/updated strings. |
| src/dotnet-ef/Project.cs | Adds stderr capture + new failure detection/exception paths in Project.FromFile. |
Files not reviewed (1)
- src/dotnet-ef/Properties/Resources.Designer.cs: Language not supported
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/d9729b3b-1743-48de-8d86-4d2f4fce31c1 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/6041fd96-1ac9-4099-ad86-052bd1d6e67d Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves dotnet-ef/ef diagnostics and messaging around project metadata extraction, especially for file-based apps, by surfacing underlying dotnet build failures and updating user-facing strings.
Changes:
- Capture
dotnet buildstderr duringProject.FromFileand surface it viaReporterso MSBuild/SDK errors aren’t dropped. - Add more actionable failures for missing input files and (heuristically) missing assets file restore scenarios.
- Update resource strings and
RootCommandverbose messaging to distinguish projects vs file-based apps; update tests to assert noerror:output on success paths.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet-ef.Tests/ProjectTest.cs | Captures Reporter output and asserts no error: prefix on success; adds missing-file test. |
| src/ef/Properties/Resources.resx | Updates CLI option descriptions to reference “project or file-based app directory”. |
| src/ef/Properties/Resources.Designer.cs | Regenerated designer for updated resource strings. |
| src/dotnet-ef/RootCommand.cs | Chooses “Using project” vs “Using file-based app” verbose messages based on file extension. |
| src/dotnet-ef/Properties/Resources.resx | Updates metadata failure text; adds RestoreRequired/ProjectFileNotFound and file-based app “Using …” messages; updates output-dir descriptions. |
| src/dotnet-ef/Properties/Resources.Designer.cs | Regenerated designer for new/updated resources. |
| src/dotnet-ef/Project.cs | Adds upfront missing-file error, captures stderr from dotnet build, and throws RestoreRequired when NETSDK1004 is detected. |
Files not reviewed (2)
- src/dotnet-ef/Properties/Resources.Designer.cs: Language not supported
- src/ef/Properties/Resources.Designer.cs: Language not supported
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Improves dotnet-ef diagnostics around Project.FromFile by surfacing underlying dotnet build failures (including stderr), providing more actionable exceptions for common failure modes, and updating user-facing messages to explicitly support file-based apps.
Changes:
- Capture
dotnet buildstderr during metadata extraction and report it viaReporterinstead of dropping it. - Throw more specific
CommandExceptions for missing files and missing restore assets (NETSDK1004). - Update resources and verbose messages to refer to “project or file-based app”, and add file-based app variants for “Using …” messages.
- Update tests to capture
Reporteroutput and assert that the success path doesn’t emit prefixed errors.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet-ef.Tests/ProjectTest.cs | Adds output-capture helper and new test for missing project file; asserts no error: prefix on success. |
| src/dotnet-ef/Project.cs | Adds missing-file guard, captures stderr, and throws more actionable exceptions (e.g., restore required). |
| src/dotnet-ef/RootCommand.cs | Chooses “Using project” vs “Using file-based app” messages based on .cs extension. |
| src/dotnet-ef/Properties/Resources.resx | Updates metadata failure message; adds new resources for restore-required, missing file, and file-based app usage messages; updates output-dir descriptions. |
| src/dotnet-ef/Properties/Resources.Designer.cs | Updates strongly-typed accessors for new/updated resources (but note: some XML doc comments are now out of sync with .resx). |
| src/ef/Properties/Resources.resx | Updates output-dir-related descriptions to mention “project or file-based app directory”. |
| src/ef/Properties/Resources.Designer.cs | Updates corresponding resource XML doc comments for the changed strings. |
Files not reviewed (2)
- src/dotnet-ef/Properties/Resources.Designer.cs: Language not supported
- src/ef/Properties/Resources.Designer.cs: Language not supported
Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/00e3bf12-20c2-4aa6-9433-209b27585fc3 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
roji
left a comment
There was a problem hiding this comment.
LGTM, is there an issue that this should reference?
This is just something I found reviewing the code |
Project.FromFileinvokeddotnet build --no-restorebut only captured stdout, throwing a single genericUnable to retrieve project metadata. Ensure it's an SDK-style project.on any non-zero exit. The actual MSBuild/SDK error went to the console and was dropped from the exception, and the message was stale now that file-based apps are supported. In addition, several other user-facing messages still referred only to "project" even when the user specified a file-based app.Changes
dotnet buildis now captured and reported viaReporter.WriteError, so the underlying MSBuild/SDK error is shown to the user instead of being silently dropped (stdout continues to flow throughReporter.WriteVerbose).ProjectFileNotFoundthrown up-front when the path doesn't exist (replaces the crypticMSB1009: Project file does not exist).RestoreRequiredthrown when captured output containsNETSDK1004(assets file missing) — the most likely cause when restore was skipped or failed silently before--no-restorebuild.GetMetadataFailednow readsUnable to retrieve project metadata. Ensure it's an SDK-style project or a file-based app.UsingFileBasedApp/UsingStartupFileBasedAppresources;RootCommandselects the appropriate variant based on the file extension (.cs→ file-based app message, otherwise project message).MigrationsOutputDirDescription,DbContextOutputDirDescription, andScaffoldOutputDirDescription(in bothdotnet-efandefresx) from "project directory" to "project or file-based app directory".Project.FromFilenow routeReporteroutput through a captured writer and assert that noerror:prefix appears on the success path.Example
Before — when restore was incomplete on the machine:
After — the actual
dotnet builderror is written to the console as an error, and a more actionable exception is thrown: