AspNet.Module.Migrator 3.0.1

dotnet add package AspNet.Module.Migrator --version 3.0.1
                    
NuGet\Install-Package AspNet.Module.Migrator -Version 3.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspNet.Module.Migrator" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspNet.Module.Migrator" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AspNet.Module.Migrator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AspNet.Module.Migrator --version 3.0.1
                    
#r "nuget: AspNet.Module.Migrator, 3.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AspNet.Module.Migrator@3.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AspNet.Module.Migrator&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AspNet.Module.Migrator&version=3.0.1
                    
Install as a Cake Tool

AspNet.Module.Migrator

Database migration package for applying EF Core migrations and running seed data.

Usage Steps

1. Create a migration DbContext

public class MigrationDbContext : AppDbContext
{
}

2. Add Microsoft.EntityFrameworkCore.Design

This enables dotnet ef migrations add and other EF Core CLI commands.

<ItemGroup>
    <PackageReference Include="AspNet.Module.Migrator" Version="3.x.x" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
</ItemGroup>

3. Create a design-time DbContext factory

public class MigrationDbContextFactory : BaseDesignTimeDbContextFactory<MigrationDbContext>
{
}

4. Generate migrations from CLI

dotnet ef migrations add Init
dotnet ef migrations remove

5. Configure the migrator in Program

var migrator = new AspNetMigrator<MigrationDbContext>(new AspNetMigratorOptions(args)
{
    Configuration = c =>
    {
#if DEBUG
        c.AddUserSecrets(Assembly.GetEntryAssembly());
#endif
    }
});

migrator.Seeds.Add<Seed1>();
migrator.Seeds.Add<Seed2>();

await migrator.RunAsync();

6. Add the migrator to a Docker image

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
RUN dotnet restore src/Some.Migrator/*.csproj
WORKDIR /app/src/Some.Migrator
RUN dotnet publish -o out -c Release --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
COPY --from=build /app/src/Some.Migrator/out ./migrate/

Seed Registration

internal class SomeSeed : ISeedDatabaseExecutor<MigrationDbContext>
{
    public int Order => 1;
    public string Name => nameof(SomeSeed);
    public bool Enabled => true;

    public Task Execute(MigrationDbContext dbContext, CancellationToken ct)
    {
        dbContext.SomeEntity.Add(...);
        return Task.CompletedTask;
    }
}
var migrator = new AspNetMigrator<MigrationDbContext>(new ConsoleMigratorConfig(...));
migrator.Seeds.Add<SomeSeed>();
await migrator.RunAsync();

Source Code

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.1 39 4/19/2026
3.0.0 41 4/19/2026