EFMigrationResourceBuilderExtensions Methods
PublishAsMigrationBundle(IResourceBuilder<EFMigrationResource>, string?, bool, bool, string?) Section titled PublishAsMigrationBundle(IResourceBuilder<EFMigrationResource>, string?, bool, bool, string?) extension IResourceBuilder<EFMigrationResource> public static class EFMigrationResourceBuilderExtensions{ public static IResourceBuilder<EFMigrationResource> PublishAsMigrationBundle( this IResourceBuilder<EFMigrationResource> builder, string? targetRuntime = null, bool selfContained = false, bool publishContainer = false, string? baseImage = null) { // ... }}Parameters
builder IResourceBuilder<EFMigrationResource> The resource builder. targetRuntime string? optional The target runtime identifier for the bundle (e.g., linux-x64, win-x64). If null and publishContainer is true, defaults to linux-x64 so the bundle can run inside a Linux container image. When publishContainer is false the current runtime is used. selfContained bool optional If true, creates a self-contained bundle that includes the .NET runtime. Never defaulted by publishContainer — user-specified value is always respected. publishContainer bool optional If true, the bundle is published as a container image that applies migrations at deploy time. The resource becomes a compute resource; each target environment deploys it the same way it deploys any other container (supplying connection strings from referenced ApplicationModel.IResourceWithConnectionString dependencies via the standard WithReference mechanism). baseImage string? optional Overrides the base container image for the generated Dockerfile. When null (the default), the image is derived from the project's target framework — for example, mcr.microsoft.com/dotnet/runtime:10.0 for a net10.0 framework-dependent bundle. Set this when the default is not suitable, e.g. for preview SDKs or custom base images. Only meaningful when publishContainer is true. Returns
IResourceBuilder<EFMigrationResource> The resource builder for chaining. Remarks
During aspire publish, the bundle executable is written to the publish output directory under the efmigrations folder. When publishContainer is true, Aspire also generates a Dockerfile that packages the bundle into a container image; the container reads the connection string from a ConnectionStrings__<name> environment variable provided by the referenced database resource (call .WithReference(db) on the migration builder, or the connection string is injected automatically for every ApplicationModel.IResourceWithConnectionString that the migration resource .WaitFor s).
PublishAsMigrationScript(IResourceBuilder<EFMigrationResource>, bool, bool) Section titled PublishAsMigrationScript(IResourceBuilder<EFMigrationResource>, bool, bool) extension IResourceBuilder<EFMigrationResource> public static class EFMigrationResourceBuilderExtensions{ public static IResourceBuilder<EFMigrationResource> PublishAsMigrationScript( this IResourceBuilder<EFMigrationResource> builder, bool idempotent = true, bool noTransactions = false) { // ... }}Parameters
builder IResourceBuilder<EFMigrationResource> The resource builder. idempotent bool optional If true (the default), generates an idempotent script with IF NOT EXISTS checks so it can be safely re-run against a database that has already had some or all of the migrations applied. noTransactions bool optional If true, omits transaction statements from the script. Returns
IResourceBuilder<EFMigrationResource> The resource builder for chaining. Remarks
aspire publish, the generated SQL script is written to the publish output directory under the efmigrations folder. The script is included as a deployment artifact, but it is not executed automatically during deployment. RunDatabaseUpdateOnStart(IResourceBuilder<EFMigrationResource>) Section titled RunDatabaseUpdateOnStart(IResourceBuilder<EFMigrationResource>) extension IResourceBuilder<EFMigrationResource> public static class EFMigrationResourceBuilderExtensions{ public static IResourceBuilder<EFMigrationResource> RunDatabaseUpdateOnStart( this IResourceBuilder<EFMigrationResource> builder) { // ... }}Parameters
builder IResourceBuilder<EFMigrationResource> The resource builder. Returns
IResourceBuilder<EFMigrationResource> The resource builder for chaining. Remarks
When enabled, migrations will be applied during AppHost startup. This only affects local run-mode execution. The migrations resource is not deployed with the app, so the command has no effect during publish or deployment.
A health check is automatically registered for this resource, allowing other resources to use .WaitFor() to wait until migrations complete before starting.
WithMigrationNamespace(IResourceBuilder<EFMigrationResource>, string) Section titled WithMigrationNamespace(IResourceBuilder<EFMigrationResource>, string) extension IResourceBuilder<EFMigrationResource> public static class EFMigrationResourceBuilderExtensions{ public static IResourceBuilder<EFMigrationResource> WithMigrationNamespace( this IResourceBuilder<EFMigrationResource> builder, string @namespace) { // ... }}Parameters
builder IResourceBuilder<EFMigrationResource> The resource builder. namespace string The namespace for generated migrations. Returns
IResourceBuilder<EFMigrationResource> The resource builder for chaining. Remarks
WithMigrationOutputDirectory(IResourceBuilder<EFMigrationResource>, string) Section titled WithMigrationOutputDirectory(IResourceBuilder<EFMigrationResource>, string) extension IResourceBuilder<EFMigrationResource> public static class EFMigrationResourceBuilderExtensions{ public static IResourceBuilder<EFMigrationResource> WithMigrationOutputDirectory( this IResourceBuilder<EFMigrationResource> builder, string outputDirectory) { // ... }}Parameters
builder IResourceBuilder<EFMigrationResource> The resource builder. outputDirectory string The output directory path relative to the project root. Returns
IResourceBuilder<EFMigrationResource> The resource builder for chaining. Remarks
WithMigrationsProject(IResourceBuilder<EFMigrationResource>, string) Section titled WithMigrationsProject(IResourceBuilder<EFMigrationResource>, string) extension IResourceBuilder<EFMigrationResource> public static class EFMigrationResourceBuilderExtensions{ public static IResourceBuilder<EFMigrationResource> WithMigrationsProject( this IResourceBuilder<EFMigrationResource> builder, string projectPath) { // ... }}Parameters
builder IResourceBuilder<EFMigrationResource> The resource builder. projectPath string The path to the project file containing the migrations. Returns
IResourceBuilder<EFMigrationResource> The resource builder for chaining. Remarks
Use this method when the migrations are in a different project than the startup project. The target project's path will be used for migration operations while the startup project remains the original project.
WithMigrationsProject(IResourceBuilder<EFMigrationResource>) Section titled WithMigrationsProject(IResourceBuilder<EFMigrationResource>) extension IResourceBuilder<EFMigrationResource> public static class EFMigrationResourceBuilderExtensions{ public static IResourceBuilder<EFMigrationResource> WithMigrationsProject<TProject>( this IResourceBuilder<EFMigrationResource> builder) { // ... }}Parameters
builder IResourceBuilder<EFMigrationResource> The resource builder. Returns
IResourceBuilder<EFMigrationResource> The resource builder for chaining. Remarks
Use this method when the migrations are in a different project than the startup project. The target project's path will be used for migration operations while the startup project remains the original project.
var migrations = project.AddEFMigrations<MyDbContext>("migrations") .WithMigrationsProject<Projects.MyMigrationsProject>();