Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Add an EFMigrationsOutputDir project property as the default --output-dir - #39568

Draft
ajcvickers wants to merge 7 commits into
dotnet:mainfrom
ajcvickers:feature/35069-migrations-output-dir-property
Draft

ajcvickers wants to merge 7 commits into
dotnet:mainfrom
ajcvickers:feature/35069-migrations-output-dir-property

Conversation

@ajcvickers

Copy link
Copy Markdown
Contributor

Stacked on #39567 (which is stacked on #39565). Until those merge, this PR also shows their commits; the new ones are the last two ("Add EFMigrationsOutputDir project property as the default --output-dir" and "Apply EFMigrationsOutputDir to migrations remove..."). It is a draft for that reason.

Adds an optional EFMigrationsOutputDir MSBuild property in the migrations project. dotnet-ef reads it and uses it as --output-dir for migrations add, database update --add and migrations remove when none is given on the command line, so a project whose migrations are not in the default Migrations folder doesn't need the option on every command. It matters more now that the snapshot follows --output-dir, and remove needs to find the files again.

<PropertyGroup>
  <EFMigrationsOutputDir>Data/Migrations</EFMigrationsOutputDir>
</PropertyGroup>
  • An explicit -o, --output-dir, --output-dir=X or -o:X always wins. Other commands are not affected.
  • The value is trimmed and its directory separators are normalized, like the other project properties (MSBuild returns it as written, including wrapped whitespace).
  • When the property supplies the directory, dotnet-ef says so at information level, because it can move the snapshot.
  • It applies to every DbContext in the project, so the README recommends leaving it unset when there is more than one context. The Package Manager Console commands don't use it yet.

Fixes #35069

🤖 Generated with Claude Code

@ajcvickers
ajcvickers force-pushed the feature/35069-migrations-output-dir-property branch 2 times, most recently from 0cb5624 to 178d66b Compare November 15, 2026 10:41
@ajcvickers
ajcvickers force-pushed the feature/35069-migrations-output-dir-property branch 2 times, most recently from 069adc6 to b35c9f8 Compare December 1, 2026 19:31
@AndriySvyryd AndriySvyryd self-assigned this Dec 1, 2026
ajcvickers and others added 7 commits December 2, 2026 12:18
migrations remove only searched under the project directory, so it could not find
migration or snapshot files placed outside of it with --output-dir, and it silently
re-created a second snapshot. Add an optional --output-dir/-OutputDir as an extra place
to look, and warn when the snapshot has to be re-created.

Part of dotnet#32738

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…utputDir

Part of dotnet#32738

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…errides of RemoveMigration working

- migrations remove now throws, before changing anything, when neither the migration file nor the snapshot file can be found, and names --output-dir.
- Locate the snapshot by namespace and class, and fail when it is declared in several files.
- Add a default interface implementation for the new IMigrationsScaffolder.RemoveMigration overload, and keep calling the original overload when there is no output directory so overrides still take effect.
- Create the directory when remove has to write a new snapshot.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…th outputDir

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ions remove

With --force on an applied migration, the files not found check ran after the migration had been reverted, so the command could revert the database and then report that nothing was removed. The files are now looked up first.

Also match snapshot declarations in namespaces that have escaped identifiers (App.@event), and only require a C# class declaration when the code generator is the C# one, so that the snapshot of other languages is found by name as before.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
dotnet ef migrations add (and database update --add) use the property when --output-dir
is not specified, so the location no longer has to be repeated on every command.

Fixes dotnet#35069

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…, and report its use

- Pass the property to migrations remove so files outside the project can be found.
- Trim whitespace and normalize directory separators, like the other project properties.
- Report the directory taken from the property as information, since it can move the snapshot.
- Document that the property applies to every DbContext in the project.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ajcvickers
ajcvickers force-pushed the feature/35069-migrations-output-dir-property branch from b35c9f8 to 84bd2a2 Compare December 2, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow --output-dir to be permanently configured.

2 participants