dotnet / dotnet/efcore

Proposal: Configure EF Core migration output directory via DbContextOptions

Open
#36,694 2 comments 0 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-tools customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### What problem are you trying to solve?

In layered solutions (Clean Architecture, modular monoliths), migration files often need to be placed under a fixed folder that reflects the architecture (e.g., `Infrastructure/Persistence/Migrations`).

Currently, EF Core only supports this via CLI flags (` -o/--output-dir `). This leads to:
- Developers forgetting to pass the flag → misplaced files
- Inconsistent migration locations across teams
- Extra scripting in CI/CD pipelines just to move files
- Configuration being tied to CLI instead of the solution itself

### Describe the solution you'd like

Allow developers to configure the migration output directory directly in `DbContextOptions`.

Example:
```
options.UseSqlServer(connectionString, x =>
x.MigrationsAssembly("AppName.Infrastructure")
.MigrationsDirectory("Persistence/Migrations"));
```

Behavior:
- Running `dotnet ef migrations add InitialCreate` (without ` -o `) places files under the configured directory.
- If no configuration is provided, fallback = current behavior (backward compatible).

✅ Benefits:
- Consistent migration locations across teams & environments
- Eliminates reliance on CLI flags
- Simplifies CI/CD automation
- Fits layered architectures cleanly
- Backward-compatible (no breaking changes)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.