In this lesson, you will learn how to use migration bundling to simplify deploying your Entity Framework Core schema changes across diverse environments without needing the full .NET SDK installed on your target servers.
Why Use Migration Bundles?
When you move your application through development, staging, and production, managing database updates can be tricky. While running dotnet ef database update works on your local machine, it is often impractical to install the entire .NET SDK or rely on dotnet-ef CLI tools on restricted production servers.
A Migration Bundle solves this by packaging your entire migration history and the EF Core migration engine into a single, platform-specific executable. This executable acts as a self-contained "deployer" that you can move to any server and run just like any other app.
Creating and Using a Bundle
To create a bundle, you use the dotnet ef migrations bundle command in your project folder. This command analyzes your DbContext and your existing migration files to produce a binary named efbundle.exe (by default).
When you are ready to update a target database, you simply copy this executable to the server and run it:
# To generate the bundle
dotnet ef migrations bundle --output ./my-deploy-tool
# To run the update on the server
./my-deploy-tool --connection "Server=my-prod-db;Database=MyApp;..."
Benefits for Diverse Environments
- Zero Dependencies: The target machine does not need the .NET SDK, the
dotnet-eftool, or even your source code. - Consistency: Because the bundle contains the exact logic for your migrations, you guarantee that the schema update behaves exactly as it did during your local testing.
- CI/CD Friendly: You can build this bundle as an artifact in your CI pipeline, store it, and trigger it as a distinct step in your deployment process. This decoupling makes your release cycle much more robust.
By treating migrations as a standalone executable artifact, you transform a complex, environment-dependent process into a simple, predictable deployment step.
Key Takeaway: Migration bundles package your migration logic into a self-contained executable, allowing you to update databases in restricted environments without requiring the .NET SDK or project source code.