Skip to content

Commit 518a7b2

Browse files
authored
feat: added the ability to split model generation across two projects for data-domain model segregation (#14)
* feat: added the ability to split model generation across two projects for data-domain model segregation - Updated README and split-outputs documentation to clarify project roles (#11, #12). - Modified DbContext template to skip foreign keys without navigation properties. - Adjusted project file configurations for Models and Data projects to improve clarity and functionality. - Updated built-in templates to be version aware. - Updated default efcpt-config.json to not exclude all objects (#16)
1 parent 95e9586 commit 518a7b2

41 files changed

Lines changed: 5873 additions & 150 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,31 @@ Automate database-first EF Core model generation as part of your build pipeline.
1313

1414
## 🚀 Quick Start
1515

16-
### Install (2-3 steps, 30 seconds)
16+
### Install (2 steps, 30 seconds)
1717

18-
**Step 1:** Add the NuGet package to your application project:
18+
**Step 1:** Add the NuGet package to your application project / class library:
1919

20-
```xml
21-
<ItemGroup>
22-
<PackageReference Include="JD.Efcpt.Build" Version="x.x.x" />
23-
</ItemGroup>
20+
```bash
21+
dotnet add package JD.Efcpt.Build
22+
```
23+
24+
**Step 2:** Build your project:
25+
26+
```bash
27+
dotnet build
2428
```
2529

26-
**Step 2:** *(Optional for .NET 10+)* Ensure EF Core Power Tools CLI is available:
30+
**That's it!** Your EF Core DbContext and entities are now automatically generated from your database project during every build.
2731

28-
> **✨ .NET 10+ Users:** The tool is automatically executed via `dnx` and does **not** need to be installed. Skip this step if you're using .NET 10.0 or later!
32+
> **✨ .NET 8 and 9 Users must install the `ErikEJ.EFCorePowerTools.Cli` tool in advance:**
2933
3034
```bash
31-
# Only required for .NET 8.0 and 9.0
3235
dotnet tool install --global ErikEJ.EFCorePowerTools.Cli --version "8.*"
3336
dotnet tool install --global ErikEJ.EFCorePowerTools.Cli --version "9.*"
3437
```
3538

39+
---
40+
3641
**Step 3:** Build your project:
3742

3843
```bash
@@ -110,7 +115,10 @@ The package orchestrates a MSBuild pipeline with these stages:
110115

111116
- **.NET SDK 8.0+** (or compatible version)
112117
- **EF Core Power Tools CLI** (`ErikEJ.EFCorePowerTools.Cli`) - **Not required for .NET 10.0+** (uses `dnx` instead)
113-
- **SQL Server Database Project** (`.sqlproj`) that compiles to DACPAC
118+
- **SQL Server Database Project** that compiles to DACPAC:
119+
- **[MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj)** - Cross-platform, works on Linux/macOS/Windows
120+
- **[Microsoft.Build.Sql](https://github.com/microsoft/DacFx)** - Cross-platform SDK-style projects
121+
- **Traditional `.sqlproj`** - Requires Windows/Visual Studio build tools
114122

115123
### Step 1: Install the Package
116124

@@ -772,6 +780,8 @@ dotnet build
772780

773781
### GitHub Actions
774782

783+
> **💡 Cross-Platform Support:** If you use [MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj) or [Microsoft.Build.Sql](https://github.com/microsoft/DacFx) for your database project, you can use `ubuntu-latest` instead of `windows-latest` runners. Traditional `.sqlproj` files require Windows build agents.
784+
775785
**.NET 10+ (Recommended - No tool installation required!)**
776786

777787
```yaml
@@ -781,7 +791,7 @@ on: [push, pull_request]
781791

782792
jobs:
783793
build:
784-
runs-on: windows-latest
794+
runs-on: windows-latest # Use ubuntu-latest with MSBuild.Sdk.SqlProj or Microsoft.Build.Sql
785795

786796
steps:
787797
- uses: actions/checkout@v3
@@ -810,7 +820,7 @@ on: [push, pull_request]
810820

811821
jobs:
812822
build:
813-
runs-on: windows-latest
823+
runs-on: windows-latest # Use ubuntu-latest with MSBuild.Sdk.SqlProj or Microsoft.Build.Sql
814824

815825
steps:
816826
- uses: actions/checkout@v3
@@ -840,7 +850,7 @@ trigger:
840850
- main
841851

842852
pool:
843-
vmImage: 'windows-latest'
853+
vmImage: 'windows-latest' # Use ubuntu-latest with MSBuild.Sdk.SqlProj or Microsoft.Build.Sql
844854

845855
steps:
846856
- task: UseDotNet@2
@@ -868,6 +878,8 @@ steps:
868878
869879
### Docker
870880
881+
> **💡 Note:** Docker builds work with [MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj) or [Microsoft.Build.Sql](https://github.com/microsoft/DacFx) database projects. Traditional `.sqlproj` files are not supported in Linux containers.
882+
871883
```dockerfile
872884
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
873885
WORKDIR /src
@@ -892,7 +904,7 @@ RUN dotnet build --configuration Release --no-restore
892904
1. **Use .NET 10+** - Eliminates the need for tool manifests and installation steps via `dnx`
893905
2. **Use local tool manifest (.NET 8-9)** - Ensures consistent `efcpt` version across environments
894906
3. **Cache tool restoration (.NET 8-9)** - Speed up builds by caching `.dotnet/tools`
895-
4. **Windows agents for DACPAC** - Database projects typically require Windows build agents
907+
4. **Cross-platform SQL projects** - Use [MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj) or [Microsoft.Build.Sql](https://github.com/microsoft/DacFx) to build DACPACs on Linux/macOS (traditional `.sqlproj` requires Windows)
896908
5. **Deterministic builds** - Generated code should be identical across builds with same inputs
897909

898910
---
@@ -1185,7 +1197,10 @@ By default the build uses `dotnet tool run efcpt` when a local tool manifest is
11851197

11861198
- .NET SDK 8.0 or newer.
11871199
- EF Core Power Tools CLI installed as a .NET tool (global or local).
1188-
- A SQL Server Database Project (`.sqlproj`) that can be built to a DACPAC. On build agents this usually requires the appropriate SQL Server Data Tools / build tools components.
1200+
- A SQL Server Database Project that compiles to a DACPAC:
1201+
- **[MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj)** - Cross-platform, works on Linux/macOS/Windows
1202+
- **[Microsoft.Build.Sql](https://github.com/microsoft/DacFx)** - Cross-platform SDK-style projects
1203+
- **Traditional `.sqlproj`** - Requires Windows with SQL Server Data Tools / build tools components
11891204

11901205
---
11911206

@@ -1451,7 +1466,7 @@ No special steps are required beyond installing the prerequisites. A typical CI
14511466

14521467
On each run the EF Core models are regenerated only when the DACPAC or EF Core Power Tools inputs change.
14531468

1454-
Ensure that the build agent has the necessary SQL Server Data Tools components to build the `.sqlproj` to a DACPAC.
1469+
> **💡 Tip:** Use [MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj) or [Microsoft.Build.Sql](https://github.com/microsoft/DacFx) to build DACPACs on Linux/macOS CI agents. Traditional `.sqlproj` files require Windows agents with SQL Server Data Tools components.
14551470

14561471
---
14571472

@@ -1468,7 +1483,8 @@ Ensure that the build agent has the necessary SQL Server Data Tools components t
14681483
### 8.2 DACPAC build problems
14691484

14701485
- Ensure that either `msbuild.exe` (Windows) or `dotnet msbuild` is available.
1471-
- Install the SQL Server Data Tools / database build components on the machine running the build.
1486+
- For **traditional `.sqlproj`** files: Install the SQL Server Data Tools / database build components on a Windows machine.
1487+
- For **cross-platform builds**: Use [MSBuild.Sdk.SqlProj](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj) or [Microsoft.Build.Sql](https://github.com/microsoft/DacFx) which work on Linux/macOS/Windows without additional components.
14721488
- Review the detailed build log from the `EnsureDacpacBuilt` task for underlying MSBuild errors.
14731489

14741490
### 8.3 `efcpt` CLI issues

0 commit comments

Comments
 (0)