Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-migration is no longer adding created migration files to project #28716

Closed
ronaldhoek opened this issue Aug 15, 2022 · 7 comments
Closed

Comments

@ronaldhoek
Copy link

After upgrading from EFCore 5.0.11 (.NET Core 3.1) to EFCore 6.0.6 (.NET 6) the 'add-migration' command no longer adds the migration scripts to the data project.

The 'Test.Data' project has the following config regarding the 'Migration' folder:

  <ItemGroup>
    <Compile Remove="Migrations\**" />
    <EmbeddedResource Remove="Migrations\**" />
    <None Remove="Migrations\**" />
  </ItemGroup>

  <ItemGroup>
    <Compile Include="Migrations\20220815082103_initial.cs" />
    <Compile Include="Migrations\20220815082103_initial.Designer.cs" />
    <Compile Include="Migrations\TestDbContextModelSnapshot.cs" />
  </ItemGroup>

Steps

  • set Test.Api as startup project
  • open Package Manager console
  • select Test.Data
  • run command add-migration next -verbose
    image

Result: script is created but not added to the [project Test.Data as it was when using .NET Core 3.1/EF 5.0.11

Package Manager Console output

Using project 'Data\Test.Data'.
Using startup project 'Test.Api'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile "E:\Projects\CHECK 2.0\TestMigrations\Test.Api\bin\Debug\net6.0\Test.Api.deps.json" --additionalprobingpath C:\Users\<user>\.nuget\packages --runtimeconfig "E:\Projects\CHECK 2.0\TestMigrations\Test.Api\bin\Debug\net6.0\Test.Api.runtimeconfig.json" C:\Users\<user>\.nuget\packages\microsoft.entityframeworkcore.tools\6.0.6\tools\netcoreapp2.0\any\ef.dll migrations add next --json --verbose --no-color --prefix-output --assembly "E:\Projects\CHECK 2.0\TestMigrations\Test.Api\bin\Debug\net6.0\Test.Data.dll" --project "E:\Projects\CHECK 2.0\TestMigrations\Test.Data\Test.Data.csproj" --startup-assembly "E:\Projects\CHECK 2.0\TestMigrations\Test.Api\bin\Debug\net6.0\Test.Api.dll" --startup-project "E:\Projects\CHECK 2.0\TestMigrations\Test.Api\Test.Api.csproj" --project-dir "E:\Projects\CHECK 2.0\TestMigrations\Test.Data\\" --language C# --configuration Debug --working-dir "E:\Projects\CHECK 2.0\TestMigrations" --root-namespace Test.Data
Using assembly 'Test.Data'.
Using startup assembly 'Test.Api'.
Using application base 'E:\Projects\CHECK 2.0\TestMigrations\Test.Api\bin\Debug\net6.0'.
Using working directory 'E:\Projects\CHECK 2.0\TestMigrations\Test.Api'.
Using root namespace 'Test.Data'.
Using project directory 'E:\Projects\CHECK 2.0\TestMigrations\Test.Data\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'Test.Api'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'TestDbContext'.
Finding DbContext classes in the project...
Using context 'TestDbContext'.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 6.0.6 initialized 'TestDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.6' with options: None
Finding design-time services referenced by assembly 'Test.Api'...
Finding design-time services referenced by assembly 'Test.Data'...
No referenced design-time services were found.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'Test.Api'...
No design-time services were found.
Writing migration to 'E:\Projects\CHECK 2.0\TestMigrations\Test.Data\Migrations\20220815083754_next.cs'.
Writing model snapshot to 'E:\Projects\CHECK 2.0\TestMigrations\Test.Data\Migrations\TestDbContextModelSnapshot.cs'.
To undo this action, use Remove-Migration.

Provider and version information

EF Core version: 6.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system:
IDE: Visual Studio 2022 17.3.0

@ronaldhoek
Copy link
Author

ronaldhoek commented Aug 15, 2022

Add test projects/solution
TestMigrations.zip

@ronaldhoek ronaldhoek changed the title add-migration is no longer adding create migration files to project add-migration is no longer adding created migration files to project Aug 15, 2022
@ajcvickers
Copy link
Member

@ronaldhoek Why are you excluding the Migrations folder from building, etc. in your project? Do the added migrations show up in the project when you don't do this?

@ronaldhoek
Copy link
Author

ronaldhoek commented Aug 16, 2022

Why are you excluding the Migrations folder from building, etc. in your project?

This was done to ensure the migration files would be added explicitly to the project and would therefore give a merge conflict when more than one PR with migration scripts we're being reviewed/merged.

Do the added migrations show up in the project when you don't do this?

Yes, but that's of course de default behavior of VS...

But as the order of files AND the fact that creating scripts based on a previous model is of great importance, the 'old' behavior (automatically adding new scripts to the project file) would be desirable (again).

@ajcvickers
Copy link
Member

@ronaldhoek This was never the intended behavior. Possibly something changed in the way we're using the VS API's, or, more likely, it was never intended there either. Either way, this is not something we plan to bring back.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2022
@ronaldhoek
Copy link
Author

Thanks for the replies and for looking into it.

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 17, 2022

@ajcvickers I think this change may be related: #24937

@ronaldhoek
Copy link
Author

@ErikEJ hmmm, looks related to my issue - but it speaks about 'conditionally' adding the created script files (in the past I already noticed, that remove-migration would not remove the file from the project - so might that also be related).
Based on what condition?

I'll add this comment also to issue #24937

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants