Skip to content

Improve dotnet-ef diagnostics#38190

Merged
AndriySvyryd merged 8 commits into
mainfrom
copilot/fix-project-metadata-retrieval
Apr 30, 2026
Merged

Improve dotnet-ef diagnostics#38190
AndriySvyryd merged 8 commits into
mainfrom
copilot/fix-project-metadata-retrieval

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

Project.FromFile invoked dotnet build --no-restore but only captured stdout, throwing a single generic Unable 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

  • Capture and surface stderr: stderr from dotnet build is now captured and reported via Reporter.WriteError, so the underlying MSBuild/SDK error is shown to the user instead of being silently dropped (stdout continues to flow through Reporter.WriteVerbose).
  • More specific exceptions:
    • ProjectFileNotFound thrown up-front when the path doesn't exist (replaces the cryptic MSB1009: Project file does not exist).
    • RestoreRequired thrown when captured output contains NETSDK1004 (assets file missing) — the most likely cause when restore was skipped or failed silently before --no-restore build.
  • Updated messages for file-based app awareness:
    • GetMetadataFailed now reads Unable to retrieve project metadata. Ensure it's an SDK-style project or a file-based app.
    • Added UsingFileBasedApp / UsingStartupFileBasedApp resources; RootCommand selects the appropriate variant based on the file extension (.cs → file-based app message, otherwise project message).
    • Updated MigrationsOutputDirDescription, DbContextOutputDirDescription, and ScaffoldOutputDirDescription (in both dotnet-ef and ef resx) from "project directory" to "project or file-based app directory".
  • Tests capture and assert on output: tests that exercise Project.FromFile now route Reporter output through a captured writer and assert that no error: prefix appears on the success path.

Example

Before — when restore was incomplete on the machine:

CommandException : Unable to retrieve project metadata. Ensure it's an SDK-style project.

After — the actual dotnet build error is written to the console as an error, and a more actionable exception is thrown:

error:   ...NETSDK1004: Assets file '...project.assets.json' not found...
CommandException : Unable to retrieve project metadata. Restore the project (e.g. by running 'dotnet restore') and try again.

Copilot AI and others added 2 commits April 29, 2026 01:57
…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>
Comment thread src/dotnet-ef/Project.cs Outdated
Comment thread src/dotnet-ef/Project.cs Outdated
Comment thread test/dotnet-ef.Tests/ProjectTest.cs Outdated
…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>
Copilot AI requested a review from AndriySvyryd April 29, 2026 04:09
@AndriySvyryd AndriySvyryd changed the title Improve dotnet-ef Project.FromFile diagnostics Improve dotnet-ef diagnostics Apr 29, 2026
@AndriySvyryd AndriySvyryd requested a review from Copilot April 29, 2026 04:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 build stderr during Project.FromFile and report it through Reporter.
  • Add more specific failure modes (ProjectFileNotFound, RestoreRequired) and update the generic metadata failure message.
  • Update dotnet-ef tests to capture Reporter output 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

Comment thread src/dotnet-ef/Project.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread src/dotnet-ef/Properties/Resources.resx
Comment thread src/dotnet-ef/Properties/Resources.resx Outdated
Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/6041fd96-1ac9-4099-ad86-052bd1d6e67d

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI requested a review from AndriySvyryd April 29, 2026 04:31
@AndriySvyryd AndriySvyryd marked this pull request as ready for review April 29, 2026 04:33
@AndriySvyryd AndriySvyryd requested a review from a team as a code owner April 29, 2026 04:33
Copilot AI review requested due to automatic review settings April 29, 2026 04:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 build stderr during Project.FromFile and surface it via Reporter so 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 RootCommand verbose messaging to distinguish projects vs file-based apps; update tests to assert no error: 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

Comment thread src/dotnet-ef/Properties/Resources.resx Outdated
Comment thread src/dotnet-ef/Properties/Resources.resx Outdated
Comment thread src/dotnet-ef/Project.cs
Comment thread test/dotnet-ef.Tests/ProjectTest.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 04:47
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 build stderr during metadata extraction and report it via Reporter instead 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 Reporter output 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

Comment thread test/dotnet-ef.Tests/ProjectTest.cs
Comment thread src/dotnet-ef/Properties/Resources.Designer.cs Outdated
Comment thread src/dotnet-ef/Properties/Resources.Designer.cs
Copy link
Copy Markdown
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, is there an issue that this should reference?

@AndriySvyryd
Copy link
Copy Markdown
Member

LGTM, is there an issue that this should reference?

This is just something I found reviewing the code

@AndriySvyryd AndriySvyryd merged commit 42f8c6b into main Apr 30, 2026
28 checks passed
@AndriySvyryd AndriySvyryd deleted the copilot/fix-project-metadata-retrieval branch April 30, 2026 18:56
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.

4 participants