Add dotnet-ef JSON config defaults and validation features#37966
Open
IMZihad21 wants to merge 2 commits intodotnet:mainfrom
Open
Add dotnet-ef JSON config defaults and validation features#37966IMZihad21 wants to merge 2 commits intodotnet:mainfrom
IMZihad21 wants to merge 2 commits intodotnet:mainfrom
Conversation
Add .config/dotnet-ef.json discovery from current directory up to repo root and apply config values for project, startup project, framework, configuration, and context when CLI options are not explicitly provided. Introduce resource-backed validation and error handling for invalid JSON, unsupported/unknown properties, invalid value types, and unreadable files. Add dotnet-ef tests for config discovery/precedence, path resolution, argument propagation, and failure scenarios. Impact: users can set consistent dotnet-ef defaults in source-controlled config with existing CLI precedence preserved, reducing repetitive command arguments without breaking current behavior.
Author
@dotnet-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR adds support for loading default dotnet ef options from a repo-local JSON config file (.config/dotnet-ef.json), applying those defaults when corresponding CLI options aren’t provided, while keeping explicit CLI arguments authoritative.
Changes:
- Introduces config discovery/loading + validation via
DotNetEfConfigLoader(walk-up discovery, path resolution, strict property validation). - Applies config defaults in
dotnet-efexecution flow (project/startup project/framework/configuration) and conditionally forwards a default--contextfor select commands. - Adds resource-backed user-facing errors and new unit tests covering discovery/precedence/path behavior and invalid/unreadable config handling.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet-ef.Tests/DotNetEfConfigTest.cs | Adds unit tests for config discovery, precedence, path resolution, and invalid/unreadable config scenarios. |
| src/dotnet-ef/RootCommand.cs | Loads config defaults and conditionally appends --context to forwarded args; adds helpers for context applicability/option detection. |
| src/dotnet-ef/Properties/Resources.resx | Adds new localized strings for config read/validation errors. |
| src/dotnet-ef/Properties/Resources.Designer.cs | Adds strongly-typed accessors for the new config error strings. |
| src/dotnet-ef/DotNetEfConfigLoader.cs | Implements config discovery, JSON parsing, validation, and relative path resolution. |
Files not reviewed (1)
- src/dotnet-ef/Properties/Resources.Designer.cs: Language not supported
Keep dbcontext optimize skip behavior based on original user arguments so config-injected defaults do not change build behavior. Recognize both '=' and ':' inline context option forms when detecting explicit CLI input, and validate config values only after dispatching on supported property names so forbidden or unknown properties report the correct error category. Add tests covering explicit inline context options, optimize skip behavior, and forbidden or unknown non-string config properties to lock in the reviewed behavior.
Author
|
Addressed all review points in the latest update.
Please re-check the updated changes. |
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 #35231
Summary
This PR adds support for loading default
dotnet efoptions from.config/dotnet-ef.json.Config is discovered by walking up from the current working directory. When a matching CLI option is not provided, values from config are used.
Supported config properties:
projectstartupProjectframeworkconfigurationcontextCLI options continue to take precedence.
Changes
src/dotnet-ef/DotNetEfConfigLoader.cs.src/dotnet-ef/RootCommand.csto apply config defaults for root options and context forwarding behavior.src/dotnet-ef/Properties/Resources.resxsrc/dotnet-ef/Properties/Resources.Designer.cstest/dotnet-ef.Tests/DotNetEfConfigTest.csfor:Config snapshot
{ "project": "src/App.Infrastructure", "startupProject": "src/App.Api", "framework": "net9.0", "configuration": "Debug", "context": "AppDbContext" }Validation
.\restore.cmd. .\activate.ps1dotnet test test/dotnet-ef.Tests/dotnet-ef.Tests.csprojResult: passed locally.
Impact
dotnet efarguments in repo workflows.Review updates
dbcontext optimizeso config-injected--contextno longer changes skip-optimization behavior.=and:forms, such as--context:Fooand-c:Foo.