When using separate migrations assembly, the output path is not relative to target project
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
## File a bug
I just moved all migrations into a separate assembly as guided by the [docs](https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/projects?tabs=dotnet-core-cli).
Project structure:
```
src/
StartupProject
DbContextProject
MigrationsProject
```
I use the following command inside `src/StartupProject` to generate idempotent script and compiled model:
```
dotnet ef migrations script -i -p ../MigrationsProject -o ./Scripts/Idempotent.sql && dotnet ef dbcontext optimize --no-build -p ../DbContextProject -o ./Model
```
Using the above command, the compiled model output will be in `src/DbContextProject/Model`. However, the idempotent script is written to `src/StartupProject/Scripts/Idempotent.sql` (relative to startup project, not target project). I would have expected the file to be written to `src/MigrationsProject/Scripts/Idempotent.sql` since the target project was set using the `-p` flag just as with the compiled model.
Edit 2024-01-15: I checked the code base and the difference between add and script is that
`dotnet migrations add` combines ProjectDir with Path: https://github.com/dotnet/efcore/blob/09b51d43b01268c15a5a2bc31c8356435d573b32/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L80
`dotnet migrations script` combines WorkingDir with Path: https://github.com/dotnet/efcore/blob/09b51d43b01268c15a5a2bc31c8356435d573b32/src/ef/Commands/MigrationsScriptCommand.cs#L33
## Workaround
This works, but I would have preferred that both the `dotnet ef migrations` and `dotnet ef dbcontext optimize` with the `-o` flag would both output into a path relative to the target project.
```
dotnet ef migrations script -i -p ../MigrationsProject -o ../MigrationsProject/Scripts/Idempotent.sql && dotnet ef dbcontext optimize --no-build -p ../DbContextProject -o ./Model
```
### Include provider and version information
EF Core version: 8.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Contributor guide
Assessment
This issue has not been assessed yet.