diff --git a/entity-framework/core/cli/dotnet.md b/entity-framework/core/cli/dotnet.md index 4d28cf8cb0..1f0e66d35c 100644 --- a/entity-framework/core/cli/dotnet.md +++ b/entity-framework/core/cli/dotnet.md @@ -2,7 +2,7 @@ title: EF Core tools reference (.NET CLI) - EF Core description: Reference guide for the Entity Framework Core .NET CLI tools author: SamMonoRT -ms.date: 11/08/2024 +ms.date: 04/22/2026 uid: core/cli/dotnet --- @@ -386,6 +386,60 @@ The following example creates a script for all migrations after the InitialCreat dotnet ef migrations script 20180904195021_InitialCreate ``` +## Configuration file + +> [!NOTE] +> This feature was introduced in EF Core 11. + +Starting with EF Core 11, `dotnet ef` can load default option values from a JSON configuration file. This reduces the need to repeat the same command-line options across multiple invocations. + +### File location and discovery + +Place a file named `dotnet-ef.json` inside a `.config` directory: + +```text +/ +└── .config/ + └── dotnet-ef.json +``` + +When `dotnet ef` runs, it walks up the directory tree from the current working directory and uses the first `.config/dotnet-ef.json` file it finds. This means you can place the file at the root of your repository and it will be used from any subdirectory. + +### Supported properties + +The configuration file is a JSON object with the following optional properties: + +```json +{ + "project": "src/App.Infrastructure", + "startupProject": "src/App.Api", + "framework": "net11.0", + "configuration": "Debug", + "context": "AppDbContext", + "runtime": "win-x64", + "verbose": true, + "noColor": false, + "prefixOutput": false +} +``` + +| Property | Type | Description | +|:-----------------|:--------|:--------------------------------------------------------------------------------------------------------------------------------------------| +| `project` | string | Relative or absolute path to the target project folder. Relative paths are resolved relative to the parent of the `.config` directory containing the file. | +| `startupProject` | string | Relative or absolute path to the startup project folder. Relative paths are resolved relative to the parent of the `.config` directory containing the file. | +| `framework` | string | The [Target Framework Moniker](/dotnet/standard/frameworks#supported-target-framework-versions) for the target framework. | +| `configuration` | string | The build configuration, for example: `Debug` or `Release`. | +| `context` | string | The `DbContext` class to use. Class name only or fully qualified with namespaces. | +| `runtime` | string | The identifier of the target runtime to restore packages for. For a list of Runtime Identifiers (RIDs), see the [RID catalog](/dotnet/core/rid-catalog). | +| `verbose` | boolean | Enable verbose output. | +| `noColor` | boolean | Disable colored console output. | +| `prefixOutput` | boolean | Prefix output lines with their severity level. | + +All properties are optional. Only include the properties you need. + +> [!NOTE] +> Explicit command-line options always take precedence over values from the configuration file. + ## Additional resources * [Migrations](xref:core/managing-schemas/migrations/index) diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index d445b2a51f..78900f1671 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -2,7 +2,7 @@ title: What's New in EF Core 11 description: Overview of new features in EF Core 11 author: roji -ms.date: 02/02/2026 +ms.date: 04/22/2026 uid: core/what-is-new/ef-core-11.0/whatsnew --- @@ -631,6 +631,32 @@ Remove-Migration -Offline Drop-Database -Connection "Server=test;Database=MyDb;..." -Force ``` + + +### Configuration file for dotnet ef + +The `dotnet ef` command-line tool now supports loading default option values from a `.config/dotnet-ef.json` configuration file. This eliminates the need to repeatedly specify the same options — such as `--project` and `--startup-project` — across every command invocation. + +When you run `dotnet ef`, the tool searches for a `.config/dotnet-ef.json` file by walking up the directory tree from the current working directory. The first file found is used. Here's an example configuration file: + +```json +{ + "project": "src/App.Infrastructure", + "startupProject": "src/App.Api", + "framework": "net11.0", + "configuration": "Debug", + "context": "AppDbContext", + "runtime": "win-x64", + "verbose": true, + "noColor": false, + "prefixOutput": false +} +``` + +Explicit command-line options always take precedence over configuration file values. Path values for `project` and `startupProject` are resolved relative to the parent of the `.config` directory containing the file. + +For more information, see [Configuration file](xref:core/cli/dotnet#configuration-file). + ## Other improvements * The EF command-line tool now writes all logging and status messages to standard error, reserving standard output only for the command's actual expected output. For example, when generating a migration SQL script with `dotnet ef migrations script`, only the SQL is written to standard output.