locked
EF Core 3 design time migrations broken by Microsoft.EntityFrameworkCore.Design DevelopmentDependency RRS feed

  • Question

  • User207877544 posted

    Using IDesignTimeDbContextFactory to generate migrations at design time, running Package Manager Console commands add-migration, update-datebase, etc.

    Microsoft.EntityFrameworkCore.Design now being a DevelopmentDependency type package, adds this to the .csproj where EFCore resides so that it cannot be referenced up the chain:

    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

    Nice idea, but this breaks running design time migration commands from PMC (which gives an error about the startup project needing Microsoft.EntityFrameworkCore.Design)

    Design time migration tooling needs a reference to Microsoft.EntityFrameworkCore.Design but the default DevelopmentDependency  entries in the .csproj file appear to be blocking.

    Temp solution - comment out the <PrivateAssets/> element in the .csproj file, then PMC migration commands work

    <!-- <PrivateAssets>all</PrivateAssets> -->

    Thursday, April 9, 2020 5:18 PM

All replies

  • User-17257777 posted

    Hi efreeman518,

    which gives an error about the startup project needing Microsoft.EntityFrameworkCore.Design

    Have you add the Microsoft.EntityFrameworkCore.Design package, Can you show us the whole error message?

    Best Regards,

    Jiadong Meng

    Monday, April 13, 2020 10:24 AM
  • User207877544 posted

    Yes I added Microsoft.EntityFrameworkCore.Design to the project (Infrastructure.Data) that has references to EFCore. I do not want any references to EFCore in the startup MVC project (ESL.Services).

    Infrastructure.Data.csproj contains:

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

    in PMC (set to the data project) - Fails: 

    PM> add-migration Initial
    Build started...
    Build succeeded.
    Your startup project 'ESL.Services' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
    PM> 

    Temp solution: comment the <PrivateAssets> element in .csproj:

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3">
    <!--<PrivateAssets>all</PrivateAssets>-->
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

    then in PMC (set to the data project) - Success:

    PM> add-migration Initial
    Build started...
    Build succeeded.
    Server=localhost;Database=db-sj-dev;Integrated Security=true;MultipleActiveResultSets=True
    To undo this action, use Remove-Migration.
    PM> 

    Monday, April 13, 2020 6:45 PM
  • User-17257777 posted

    Hi efreeman518,

    I found a similiar problem with yours, which add the following entry to PropertyGroup section in your .csproj file.

    <GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>

    For more details, you can refer to this link https://stackoverflow.com/a/58185466/11965297

    Best Regards,

    Jiadong Meng

    Friday, April 17, 2020 3:12 AM
  • User207877544 posted

    I tried adding

    <GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>

    to the EntityFramework project .csproj file (also tried the startup mvc .csproj) with no luck - makes no difference, still errors with design time migration commands in PMC.

    Still, the only change that makes it work is making this change in the EF project .csproj file under the Microsoft.EntityFrameworkCore.Design PackageReference:

    <!--<PrivateAssets>all</PrivateAssets>-->

    Saturday, April 18, 2020 12:59 AM