Open jholovacs opened 6 years ago
Not that straightforward to do manually. We have ended up using the VSTS task from Ben Day, he's also published scripts for win/linux to execute the migrations. https://www.benday.com/2018/07/05/deploy-entity-framework-core-2-1-migrations-from-a-dll/
See also the discussion here: https://github.com/aspnet/EntityFrameworkCore/issues/13339
Specifically, it would be useful to:
benday's tool: Build & Release Tools
I'm doing a workaround now by creating an idempotent migration script in my build:
dotnet ef migrations script --idempotent --output "$(Build.ArtifactStagingDirectory)/migrations.sql" --context MySolution.MyDataAccessProject.Services.AnalysisDbContext
...then I run this like any other sql script in a powershell window. It seems a little kludgy, but... eh, it works.
We are working in .net 4.8 environment and using next workaround. In csproj file with migrations we are coping all dependencies to output folder:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
<IncludeAssets>compile; runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<Publish>true</Publish>
</PackageReference>
...
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9" GeneratePathProperty="true">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
...
<ItemGroup>
<None Include="$(PkgMicrosoft_EntityFrameworkCore_Tools)\tools\net461\any\ef.exe" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
So we don't need to know where is Microsoft.EntityFrameworkCore.Tools
installed and we can run migrations much easily.
With powershell something like that:
.\ef.exe database update --assembly <assembly name>.dll
with dotnet core you can do the same, all you need is replace ef.exe
path with ef.dll
path, something like that: \tools\netcoreapp2.0\any\ef.dll
I keep getting told the project can't be found. Why is the project necessary? The code is contained in the dlls. How do I take my published code as an artifact and run the database update?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.