EF Code First Migrations failure in VS 2022
alexmaie opened this issue · comments
Hi EF6 Team,
I have to reopen this ticket: #1870
I know and understand that EF6 is not being actively maintained, but since you created a netstandard 2.1 compatible version of EF6, then you also need to make sure that we can still create migrations. Right now our only option is to use VS 2019 and and to create a slim solution which only contains some older code related to EF since we can't run net6 code in VS 2019
@alexmaie, ha-ha, I bet they regret they made netstandard 2.1.
You can create migrations using small hacks.
<PropertyGroup>
<EF6>false</EF6>
<EF6Command>[command required]</EF6Command>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.4.4" GeneratePathProperty="true" />
</ItemGroup>
<Target Name="Migration" AfterTargets="Publish" Condition="$(EF6) AND '$(TargetFramework)' != 'net48'">
<Message Text="Executing EF6 command:" Importance="high" />
<!-- I'm using Microsoft.Data.SqlClient, it may not be needed in your case -->
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(PublishDir)runtimes\win\lib\netcoreapp3.1\Microsoft.Data.SqlClient.dll" DestinationFiles="$(MSBuildProjectDirectory)\$(PublishDir)Microsoft.Data.SqlClient.dll" Condition="'$(OS)' == 'Windows_NT'" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(PublishDir)runtimes\win-x64\native\Microsoft.Data.SqlClient.SNI.dll" DestinationFiles="$(MSBuildProjectDirectory)\$(PublishDir)Microsoft.Data.SqlClient.SNI.dll" Condition="'$(OS)' == 'Windows_NT'" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(PublishDir)runtimes\win-x64\native\sni.dll" DestinationFiles="$(MSBuildProjectDirectory)\$(PublishDir)sni.dll" Condition="'$(OS)' == 'Windows_NT'" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(PublishDir)runtimes\unix\lib\net6.0\Microsoft.Data.SqlClient.dll" DestinationFiles="$(MSBuildProjectDirectory)\$(PublishDir)Microsoft.Data.SqlClient.dll" Condition="'$(OS)' != 'Windows_NT'" />
<Copy SourceFiles="$(PkgEntityFramework)\tools\netcoreapp3.0\any\ef6.dll" DestinationFiles="$(MSBuildProjectDirectory)\$(PublishDir)ef6.dll" />
<Copy SourceFiles="$(MSBuildProjectDirectory)\ef6.runtimeconfig.json" DestinationFiles=" $(MSBuildProjectDirectory)\$(PublishDir)ef6.runtimeconfig.json" />
<!-- todo: change DAL.Model.dll to your dll -->
<Message Text="dotnet exec --runtimeconfig $(MSBuildProjectDirectory)\$(PublishDir)ef6.runtimeconfig.json $(MSBuildProjectDirectory)\$(PublishDir)ef6.dll $(EF6Command) --assembly $(MSBuildProjectDirectory)\$(PublishDir)DAL.Model.dll --project-dir $(MSBuildProjectDirectory)" Importance="high" />
<Exec Command="dotnet exec --runtimeconfig $(MSBuildProjectDirectory)\$(PublishDir)ef6.runtimeconfig.json $(MSBuildProjectDirectory)\$(PublishDir)ef6.dll $(EF6Command) --assembly $(MSBuildProjectDirectory)\$(PublishDir)DAL.Model.dll --project-dir $(MSBuildProjectDirectory)" WorkingDirectory="$(MSBuildProjectDirectory)\$(PublishDir)" ConsoleToMSBuild="true" />
</Target>
ef6.runtimeconfig.json
:
{
"runtimeOptions": {
"tfm": "netcoreapp3.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "7.0.0"
}
}
}
dotnet publish -c Debug --framework NET7.0 /p:ef6=true /p:EF6Command="migrations add MigrationName"
This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.