dotnet ef migrations bundle builds a single executable (efbundle) that contains your compiled migrations and applies the pending ones to whatever connection string you pass (./efbundle --connection "..."). The target machine needs no .NET SDK, no source and no dotnet-ef tool; with --self-contained -r linux-x64 it does not even need the .NET runtime. It runs migrations idempotently against __EFMigrationsHistory, so it fits a CI/CD release stage or a Kubernetes job. Choose an idempotent SQL script (dotnet ef migrations script --idempotent) instead when a DBA must review and run the SQL, when change control requires the exact statements as an artefact, or when the pipeline cannot reach the database with an executable. Both are better than Database.Migrate() at app start-up.
"A migration bundle is my migrations compiled into one executable. In CI I run
dotnet ef migrations bundle --self-contained -r linux-x64 -o efbundlefrom the same commit as the app, publish it as an artefact, and the release stage runs./efbundle --connection $CONNbefore the new app version is rolled out. The target needs nothing installed, and the bundle checks__EFMigrationsHistoryso it only applies what is pending.The alternative is an idempotent SQL script,
dotnet ef migrations script --idempotent. I pick the script when a DBA or a change board wants to read and run the exact SQL, or when the deployment agent cannot execute arbitrary binaries against production. The bundle is better when the pipeline is fully automated, because it is one step, it handles migrations that contain C# logic, and there is no copy-paste of SQL between environments.Either way I avoid
Database.Migrate()at start-up: several instances race on the schema, and the running app would need DDL rights. One more detail: keep thedotnet-eftool version aligned with the EF Core package version, otherwise the bundle build can fail or behave differently."
| Migration bundle | Idempotent SQL script | |
|---|---|---|
| Artefact | Executable | .sql file |
| Needs on target | Nothing (self-contained) or the .NET runtime | sqlcmd, SSMS or a pipeline SQL task |
| Human review | Harder (inspect via script generation) | Easy |
| Migrations with custom C# | Supported | Only what was rendered to SQL |
| Best for | Automated CI/CD, containers, Kubernetes jobs | DBA-gated or regulated releases |
dotnet ef migrations bundle --project src/Infrastructure --startup-project src/Api \
--self-contained -r linux-x64 -o artifacts/efbundle --force
./artifacts/efbundle --connection "$AZURE_SQL_CONNECTION"
Moving from start-up Migrate() to a bundle step in Azure DevOps removed [occasional] deadlocks when [four] App Service instances started together, and gave a clear failed stage instead of crashing pods.
Checks knowledge of deployment options.
Last updated 23 Nov 2026.