MSBuild integration for EF Core Power Tools CLI
Automate database-first EF Core model generation during dotnet build. Zero manual steps, full CI/CD support, reproducible builds.
dotnet new install JD.Efcpt.Build.Templates
dotnet new efcptbuild --name MyDataProject
dotnet build<Project Sdk="JD.Efcpt.Sdk/PACKAGE_VERSION">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>dotnet add package JD.Efcpt.Build
dotnet build.NET 8-9 users: Install the CLI tool first:
dotnet tool install -g ErikEJ.EFCorePowerTools.Cli --version "10.*".NET 10+ users: No tool installation needed - uses
dnxautomatically.
The complete workflow from database to EF Core models, with scaffolding as a build-time step:
graph LR
K["Entry Points"]
K -->|Template| L["dotnet new efcptbuild"]
K -->|SDK| M["Project Sdk=JD.Efcpt.Sdk"]
K -->|Package| N["PackageReference JD.Efcpt.Build"]
L & M & N -->|dotnet build| Build["<b>Build Process<br/>(BeforeTargets=CoreCompile)</b>"]
A["Live Database"] -->|Connection| B["Query Schema"]
C["SQL Project (.sqlproj)"] -->|Build| D["DACPAC"]
Direct["Direct DACPAC<br/>(EfcptDacpacPath)"] -->|DACPAC File| D
B & D -->|Schema Metadata| Build
F["Configuration<br/>(efcpt-config.json)"] -->|Config| Build
G["T4 Templates"] -->|Templates| Build
Build -->|Generate Code| H["EF Core Models"]
H -->|Compile| I["Assembly<br/>(.dll/.exe)"]
| Package | Purpose | Usage |
|---|---|---|
| JD.Efcpt.Build | MSBuild integration | Add as PackageReference |
| JD.Efcpt.Sdk | SDK package (cleanest setup) | Use as project SDK |
| JD.Efcpt.Build.Templates | Project templates | dotnet new install |
| Package | Purpose | Usage |
|---|---|---|
| JD.Efcpt.Build | MSBuild integration | Add as PackageReference |
| JD.Efcpt.Sdk | SDK package (cleanest setup) | Use as project SDK |
| JD.Efcpt.Build.Templates | Project templates | dotnet new install |
- Automatic generation - DbContext and entities generated during
dotnet build - Incremental builds - Only regenerates when schema or config changes
- Database-First SqlProj Generation - Extract schema from live databases to DACPAC (NEW!)
- Dual input modes - Works with SQL Projects (.sqlproj) or live database connections
- Smart discovery - Auto-finds database projects and configuration files
- T4 template support - Customize code generation with your own templates
- Multi-schema support - Generate models across multiple database schemas
- CI/CD ready - Works everywhere .NET runs (GitHub Actions, Azure DevOps, Docker)
- Cross-platform SQL Projects - Supports Microsoft.Build.Sql and MSBuild.Sdk.SqlProj
| Topic | Description |
|---|---|
| Getting Started | Installation and first project setup |
| Using the SDK | SDK approach for cleanest project files |
| Configuration | MSBuild properties and JSON config options |
| Connection String Mode | Generate from live databases |
| T4 Templates | Customize code generation |
| CI/CD Integration | GitHub Actions, Azure DevOps, Docker |
| Troubleshooting | Common issues and solutions |
| API Reference | Complete MSBuild properties and tasks |
| Core Concepts | How the build pipeline works |
| Architecture | Internal architecture details |
| Feature | JD.Efcpt.Build | dotnet ef dbcontext scaffold |
EF Core Power Tools GUI | Plain efcpt CLI |
|---|---|---|---|---|
| Build-time automation | Yes (MSBuild target) | Manual only | Manual only | Manual only |
| Incremental regeneration | Yes (fingerprinting) | N/A | No | No |
| DACPAC/.sqlproj support | Yes (SQL Server) | No | Yes (GUI-only) | Yes |
| Live DB input | Yes | Yes | Yes | Yes |
| Config persisted | Yes (efcpt-config.json, auto-applied) | Per-command args | efcpt-config.json (manual re-run) | efcpt-config.json (manual re-run) |
| CI/CD ready | Yes (fully automated) | Limited | No | Limited |
| T4 template customization | Yes | No | Yes | Yes |
| Multi-schema support | Yes | Yes | Yes | Yes |
Use JD.Efcpt.Build when you want automated, reproducible model generation as part of your build pipeline. Use the CLI directly when you need occasional scaffolding without build-step integration.
JD.Efcpt.Build supports multiple database providers through EF Core Power Tools:
- SQL Server (.sqlproj) - Full support: DACPAC, connection string mode, incremental builds
- PostgreSQL, MySQL, SQLite, Oracle, Firebird, Snowflake - Connection string mode only (no DACPAC generation)
Note: Traditional (non-SDK-style)
.sqlprojbuilds are Windows-only. For cross-platform SQL projects, use Microsoft.Build.Sql or MSBuild.Sdk.SqlProj (both cross-platform). DACPAC files are SQL Server-specific. For non-SQL-Server databases, use Connection String Mode to scaffold directly from a live database connection.
For detailed provider-specific guidance, see Provider Configuration.
- .NET SDK 8.0+
- EF Core Power Tools CLI - Auto-executed via
dnxon .NET 10+; requires manual install on .NET 8-9 - Database source - SQL Server Database Project (.sqlproj) or live database connection
| Type | Extension | Cross-Platform |
|---|---|---|
| Microsoft.Build.Sql | .sqlproj |
Yes |
| MSBuild.Sdk.SqlProj | .csproj / .fsproj |
Yes |
| Traditional SQL Projects | .sqlproj |
Windows only |
Automatically generate SQL scripts from your live database when JD.Efcpt.Build detects it's referenced in a SQL project:
DatabaseProject (SQL):
<Project Sdk="MSBuild.Sdk.SqlProj/3.3.0">
<PropertyGroup>
<EfcptConnectionString>Server=...;Database=MyDb;...</EfcptConnectionString>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JD.Efcpt.Build" Version="PACKAGE_VERSION" />
</ItemGroup>
</Project>DataAccessProject (EF Core):
<ItemGroup>
<ProjectReference Include="..\DatabaseProject\DatabaseProject.csproj" />
<PackageReference Include="JD.Efcpt.Build" Version="PACKAGE_VERSION" />
</ItemGroup>This enables the complete two-project workflow:
Live Database → SQL Scripts (in SQL Project) → DACPAC → EF Core Models (in DataAccess Project)
Benefits:
- ✅ Automatic SQL project detection (no configuration needed)
- ✅ Database as source of truth
- ✅ Human-readable SQL scripts for review and version control
- ✅ Clean separation: Database project (schema) + DataAccess project (models)
- ✅ Incremental builds with schema fingerprinting
- ✅ Works with .NET 10+
dnx(no sqlpackage installation required)
See the Database-First SQL Generation sample for a complete example.
See the samples directory for complete working examples:
- Simple Generation - Basic DACPAC-based generation
- SDK Zero Config - Minimal SDK project setup
- Database-First SQL Generation - Auto-generate SQL scripts from live database (NEW!)
- Connection String Mode - Generate from live database
- Custom Renaming - Table and column renaming
- Schema Organization - Multi-schema folder structure
- Split Outputs - Separate Models and Data projects
Contributions are welcome! Please open an issue first to discuss changes. See CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License. See LICENSE for details.
- EF Core Power Tools by Erik Ejlskov Jensen - The tool this package automates
- Microsoft - For Entity Framework Core and MSBuild
- GitHub Issues - Bug reports and feature requests
- GitHub Discussions - Questions and community support