This directory contains sample projects demonstrating various usage patterns of JD.Efcpt.Build for automatic Entity Framework Core model generation during MSBuild.
| Sample | Description | Key Features |
|---|---|---|
| sdk-zero-config | JD.Efcpt.Sdk as MSBuild SDK | Cleanest setup, SDK-style project |
| Sample | SQL SDK / Provider | Key Features |
|---|---|---|
| microsoft-build-sql-zero-config | Microsoft.Build.Sql | Zero-config with official MS SDK |
| dacpac-zero-config | Pre-built .dacpac | Zero-config direct DACPAC |
| simple-generation | Traditional SQL Project (.sqlproj) | Basic usage, direct source import |
| msbuild-sdk-sql-proj-generation | MSBuild.Sdk.SqlProj (.csproj) | Modern cross-platform SQL SDK |
| split-data-and-models-between-multiple-projects | Traditional SQL Project (.sqlproj) | Clean architecture, split outputs |
| custom-renaming | Microsoft.Build.Sql | Entity/property renaming rules |
| schema-organization | Microsoft.Build.Sql | Schema-based folders and namespaces |
| Sample | Database Provider | Key Features |
|---|---|---|
| connection-string-sqlite | SQLite | Direct database reverse engineering |
| connection-string-mssql | SQL Server + Aspire | SQL Server container with .NET Aspire |
| aspnet-core-appsettings | SQL Server + Aspire | appsettings.json + Aspire container |
JD.Efcpt.Build supports two primary input modes:
Reverse engineers from a SQL Project that produces a .dacpac file.
JD.Efcpt.Build supports multiple SQL Project SDKs:
| SDK | Extension | Cross-Platform | Notes |
|---|---|---|---|
| Microsoft.Build.Sql | .sqlproj |
Yes | Microsoft's official SDK-style SQL Projects for .NET |
| MSBuild.Sdk.SqlProj | .csproj or .fsproj |
Yes | Community SDK with additional features and extensibility |
| Traditional SQL Projects | .sqlproj |
No (Windows only) | Legacy format, requires SQL Server Data Tools |
<ItemGroup>
<ProjectReference Include="..\Database\Database.sqlproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<!-- Use .sqlproj for Microsoft.Build.Sql -->
<!-- Use .csproj or .fsproj for MSBuild.Sdk.SqlProj -->
</ItemGroup>Key Differences:
- Microsoft.Build.Sql uses
.sqlprojextension and is Microsoft's official SDK - MSBuild.Sdk.SqlProj uses
.csproj/.fsprojextension (despite having "SqlProj" in its name) - Both produce DACPACs and work identically with JD.Efcpt.Build
Reverse engineers directly from a live database connection.
Location: sdk-zero-config/
Demonstrates the cleanest possible setup using JD.Efcpt.Sdk as an MSBuild SDK instead of a PackageReference. This is the recommended approach for dedicated EF Core model generation projects.
sdk-zero-config/
├── SdkZeroConfigSample.sln
├── DatabaseProject/
│ ├── DatabaseProject.csproj # Microsoft.Build.Sql project
│ └── dbo/Tables/*.sql
└── EntityFrameworkCoreProject/
└── EntityFrameworkCoreProject.csproj # Uses JD.Efcpt.Sdk/PACKAGE_VERSION
Key Features:
- Uses
JD.Efcpt.Sdkas project SDK (not PackageReference) - Extends
Microsoft.NET.Sdkwith EF Core Power Tools integration - Automatic SQL project detection via
ProjectReference - Zero configuration required
Project File:
<Project Sdk="JD.Efcpt.Sdk/PACKAGE_VERSION">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DatabaseProject\DatabaseProject.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>None</OutputItemType>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.11" />
</ItemGroup>
</Project>Build:
dotnet build sdk-zero-config/SdkZeroConfigSample.slnLocation: microsoft-build-sql-zero-config/
Demonstrates true zero-configuration usage with Microsoft's official Microsoft.Build.Sql SDK. Just add JD.Efcpt.Build to your project - no efcpt-config.json, no templates, no project references needed.
Key Features:
- Zero configuration - no efcpt-config.json, templates, or project references
- Uses Microsoft's official
Microsoft.Build.SqlSDK (cross-platform) - Automatic SQL project discovery from solution
- Default sensible configuration applied automatically
Build:
dotnet build microsoft-build-sql-zero-config/ZeroConfigMsBuildSql.slnLocation: dacpac-zero-config/
Demonstrates zero-configuration reverse engineering directly from a pre-built .dacpac file. Ideal when you receive a DACPAC from a DBA or CI/CD pipeline.
Key Features:
- Zero configuration - no efcpt-config.json or templates
- Uses pre-built DACPAC file (no SQL project in solution)
- Simply set
EfcptDacpacproperty to point to the .dacpac file - No build step for SQL project - just reverse engineering
Build:
dotnet build dacpac-zero-config/ZeroConfigDacpac.slnLocation: simple-generation/
Basic sample demonstrating DACPAC-based model generation with direct source import (useful for development).
simple-generation/
├── DatabaseProject/ # SQL Project
│ └── DatabaseProject.sqlproj # Traditional format
├── EntityFrameworkCoreProject/
│ ├── EntityFrameworkCoreProject.csproj
│ ├── efcpt-config.json
│ └── Template/ # T4 templates
└── SimpleGenerationSample.sln
Build:
dotnet build simple-generation/SimpleGenerationSample.slnLocation: msbuild-sdk-sql-proj-generation/
Demonstrates using MSBuild.Sdk.SqlProj for cross-platform DACPAC builds. This SDK uses .csproj extension (not .sqlproj).
msbuild-sdk-sql-proj-generation/
├── DatabaseProject/ # MSBuild.Sdk.SqlProj project
│ └── DatabaseProject.csproj # Uses .csproj extension
├── EntityFrameworkCoreProject/
│ ├── EntityFrameworkCoreProject.csproj
│ └── efcpt-config.json
└── SimpleGenerationSample.sln
Key Features:
- Uses
MSBuild.Sdk.SqlProjSDK for the SQL Project (note: uses.csprojextension) - Works on Windows, Linux, and macOS
- Dynamic SQL Project discovery (no explicit reference needed)
Note: Despite having "SqlProj" in its name, MSBuild.Sdk.SqlProj uses
.csprojor.fsprojextensions, not.sqlproj.
Location: split-data-and-models-between-multiple-projects/
Advanced sample showing how to split generated output across multiple projects following clean architecture principles.
split-data-and-models-between-multiple-projects/
└── src/
├── SampleApp.Sql/ # SQL Project (Microsoft.Build.Sql format)
├── SampleApp.Models/ # Entity classes only (NO EF Core)
└── SampleApp.Data/ # DbContext + EF Core dependencies
Key Features:
EfcptSplitOutputs=trueenables split generation- Models project has no EF Core dependency
- DbContext and configurations go to Data project
- Automatic file distribution during build
Location: custom-renaming/
Demonstrates using efcpt.renaming.json to rename database objects to clean C# names. Useful for legacy databases with naming conventions like tbl prefixes or snake_case columns.
custom-renaming/
├── DatabaseProject/ # SQL Project with legacy-named tables
│ └── dbo/Tables/
│ ├── tblCustomers.sql # Legacy tbl prefix
│ ├── tblOrders.sql
│ └── tblOrderItems.sql
├── EntityFrameworkCoreProject/
│ ├── EntityFrameworkCoreProject.csproj
│ ├── efcpt-config.json
│ └── efcpt.renaming.json # Renaming rules
└── CustomRenaming.sln
Key Features:
- Renames tables:
tblCustomers→Customer - Renames columns:
cust_id→Id,cust_first_name→FirstName - Renaming file is auto-discovered by convention
- Schema-level
UseSchemaNamesetting
Configuration (efcpt.renaming.json):
[
{
"SchemaName": "dbo",
"UseSchemaName": false,
"Tables": [
{
"Name": "tblCustomers",
"NewName": "Customer",
"Columns": [
{ "Name": "cust_id", "NewName": "Id" },
{ "Name": "cust_first_name", "NewName": "FirstName" }
]
}
]
}
]Build:
dotnet build custom-renaming/CustomRenaming.slnLocation: schema-organization/
Demonstrates organizing generated entities by database schema using folder and namespace organization.
schema-organization/
├── DatabaseProject/
│ ├── dbo/Tables/Customer.sql
│ ├── sales/Tables/Order.sql
│ ├── sales/Tables/OrderItem.sql
│ ├── inventory/Tables/Product.sql
│ └── inventory/Tables/Warehouse.sql
├── EntityFrameworkCoreProject/
│ ├── EntityFrameworkCoreProject.csproj
│ └── efcpt-config.json
└── SchemaOrganization.sln
Key Features:
use-schema-folders-preview: Creates subdirectories per schema (Models/dbo/,Models/sales/)use-schema-namespaces-preview: Adds schema to namespace (EntityFrameworkCoreProject.Models.Sales)- Useful for large databases with multiple schemas
Generated Output:
obj/efcpt/Generated/Models/
├── dbo/
│ └── Customer.g.cs # namespace: *.Models.Dbo
├── sales/
│ ├── Order.g.cs # namespace: *.Models.Sales
│ └── OrderItem.g.cs
└── inventory/
├── Product.g.cs # namespace: *.Models.Inventory
└── Warehouse.g.cs
Configuration (efcpt-config.json):
{
"file-layout": {
"output-path": "Models",
"use-schema-folders-preview": true,
"use-schema-namespaces-preview": true
}
}Build:
dotnet build schema-organization/SchemaOrganization.slnLocation: connection-string-sqlite/
Demonstrates connection string mode with SQLite - no SQL Project needed, reverse engineers directly from a database.
Location: connection-string-mssql/
Demonstrates connection string mode with SQL Server using .NET Aspire to manage a SQL Server container.
connection-string-mssql/
├── ConnectionStringMssql.AppHost/ # Aspire orchestrator
├── EntityFrameworkCoreProject/ # EF Core project with JD.Efcpt.Build
├── Database/
│ └── init.sql # Database initialization
└── ConnectionStringMssql.sln
Key Features:
- SQL Server runs in Docker, managed by Aspire
- No external database dependencies
- Uses
EfcptProviderandEfcptConnectionStringproperties
Quick Start:
# 1. Start the SQL Server container
dotnet run --project ConnectionStringMssql.AppHost
# 2. Initialize the database
sqlcmd -S localhost,11433 -U sa -P "YourStrong@Passw0rd" -i Database/init.sql
# 3. Build the EF Core project
dotnet build EntityFrameworkCoreProjectPrerequisites: Docker Desktop, .NET 9.0 SDK
Location: aspnet-core-appsettings/
Demonstrates reading connection strings from appsettings.json with .NET Aspire managing the SQL Server container.
aspnet-core-appsettings/
├── AspNetCoreAppSettings.AppHost/ # Aspire orchestrator
├── MyApp.Api/
│ ├── MyApp.Api.csproj
│ ├── appsettings.json # Connection string for build
│ └── Program.cs
├── Database/
│ └── init.sql # Database initialization
└── AspNetCoreAppSettings.sln
Key Features:
- Uses
EfcptAppSettingsto read connection string from appsettings.json - SQL Server runs in Docker, managed by Aspire
- Works with ASP.NET Core configuration patterns
Configuration (csproj):
<PropertyGroup>
<EfcptAppSettings>appsettings.json</EfcptAppSettings>
<EfcptConnectionStringName>DefaultConnection</EfcptConnectionStringName>
<EfcptProvider>mssql</EfcptProvider>
</PropertyGroup>Quick Start:
# 1. Start the SQL Server container
dotnet run --project AspNetCoreAppSettings.AppHost
# 2. Initialize the database
sqlcmd -S localhost,11434 -U sa -P "YourStrong@Passw0rd" -i Database/init.sql
# 3. Build the API project
dotnet build MyApp.ApiPrerequisites: Docker Desktop, .NET 9.0 SDK
All samples use:
- T4 Templates for code generation (customizable)
- efcpt-config.json for EF Core Power Tools configuration
- efcpt.renaming.json for entity/property renaming rules (optional)
- Fingerprint-based incremental builds - only regenerates when schema changes
Note: The zero-config samples (
microsoft-build-sql-zero-configanddacpac-zero-config) use sensible defaults and don't require any configuration files.
- Clone the repository
- Choose a sample that matches your use case
- Build the solution:
dotnet build <sample-name>/<solution-file>.sln
- Check the generated files in
obj/efcpt/Generated/