MSBuild.Sdk.PostgreSql
1.0.0
dotnet add package MSBuild.Sdk.PostgreSql --version 1.0.0
NuGet\Install-Package MSBuild.Sdk.PostgreSql -Version 1.0.0
<PackageReference Include="MSBuild.Sdk.PostgreSql" Version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="MSBuild.Sdk.PostgreSql" Version="1.0.0" />
<PackageReference Include="MSBuild.Sdk.PostgreSql"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add MSBuild.Sdk.PostgreSql --version 1.0.0
#r "nuget: MSBuild.Sdk.PostgreSql, 1.0.0"
#:package MSBuild.Sdk.PostgreSql@1.0.0
#addin nuget:?package=MSBuild.Sdk.PostgreSql&version=1.0.0
#tool nuget:?package=MSBuild.Sdk.PostgreSql&version=1.0.0
MSBuild.Sdk.PostgreSql
MSBuild SDK for PostgreSQL Database Projects
Build SQL Server-style database projects for PostgreSQL! This SDK enables you to organize your PostgreSQL schema as code in a .csproj file, and automatically compile it to a deployable .pgpac package during build.
Features
✅ Convention over Configuration - Auto-discovers SQL files
✅ MSBuild Integration - Works with dotnet build and Visual Studio
✅ Incremental Builds - Only rebuilds when SQL files change
✅ Validation - Checks dependencies and circular references
✅ Portable Packages - Generates .pgpac files (PostgreSQL Data-tier Application Package)
✅ CI/CD Ready - Perfect for DevOps pipelines
Quick Start
Before You Start
- There is no separate Visual Studio project template installer for
preview8. - Create the
.csprojmanually or generate one withpgpac extract. - To open the project in Visual Studio, make sure the solution can restore
MSBuild.Sdk.PostgreSqlfromnuget.orgor a local package feed.
1. Create a Database Project
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="MSBuild.Sdk.PostgreSql" Version="1.0.0-preview8" />
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<DatabaseName>MyDatabase</DatabaseName>
</PropertyGroup>
</Project>
2. Organize SQL Files
MyDatabase/
├── MyDatabase.csproj
├── Tables/
│ ├── Users.sql
│ └── Orders.sql
├── Views/
│ └── ActiveOrders.sql
└── Functions/
└── CalculateTotal.sql
3. Build
dotnet build
Output:
bin/Debug/net10.0/MyDatabase.pgpac
Project Structure
Automatic SQL Discovery
All .sql files are automatically included! Organize them however you want:
MyDatabase/
├── Tables/ ✅ Discovered
├── Views/ ✅ Discovered
├── Functions/ ✅ Discovered
├── Types/ ✅ Discovered
├── Sequences/ ✅ Discovered
├── Triggers/ ✅ Discovered
└── YourFolder/ ✅ Discovered
These files and folders also stay visible in Visual Studio's Solution Explorer without needing explicit <Content Include="**\*.sql" /> entries. Standard SDK excludes such as bin/, obj/, and .vs/ remain hidden.
Pre/Post Deployment Scripts
Only these need explicit configuration:
<ItemGroup>
<PreDeploy Include="Scripts\PreDeployment\*.sql" />
<PostDeploy Include="Scripts\PostDeployment\*.sql" />
</ItemGroup>
Configuration
Properties
| Property | Default | Description |
|---|---|---|
DatabaseName |
Project name | Database name in .pgpac |
OutputFormat |
pgpac |
Output format: pgpac or json |
ValidateOnBuild |
true |
Validate SQL during build |
PgPacToolVerbose |
false |
Route verbose pgpac compile logging into the build output |
PgPacFileName |
{DatabaseName}.pgpac |
Output file name |
Example
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="MSBuild.Sdk.PostgreSql" Version="1.0.0-preview8" />
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<DatabaseName>ProductionDB</DatabaseName>
<OutputFormat>pgpac</OutputFormat>
<ValidateOnBuild>true</ValidateOnBuild>
<PgPacToolVerbose>false</PgPacToolVerbose>
</PropertyGroup>
<ItemGroup>
<PreDeploy Include="Scripts\PreDeployment\BackupData.sql" />
<PostDeploy Include="Scripts\PostDeployment\SeedData.sql" />
</ItemGroup>
</Project>
Build Integration
dotnet CLI
# Build
dotnet build
# Build with detailed pgpac CLI logging
dotnet build /p:PgPacToolVerbose=true
# Clean
dotnet clean
# Rebuild
dotnet rebuild
Visual Studio
- Open the
.csprojdirectly or add it to an existing solution - If you are testing a local packed SDK, add a
nuget.configwith your local feed before opening the project - Run
dotnet restoreif Visual Studio reports the SDK cannot be resolved - Press Ctrl+Shift+B to build
- Output appears in
bin\Debug\net10.0\ - Set
PgPacToolVerbose=truein the project or pass it as an MSBuild property when you need the build to show verbosepgpac compilediagnostics
Shared Build Engine
SDK builds now run through the packaged pgpac compile host instead of calling the DAC library directly. This keeps MSBuild builds aligned with the CLI behavior and makes verbose compile diagnostics easier to enable consistently.
CI/CD
# GitHub Actions
- name: Build Database
run: dotnet build MyDatabase/MyDatabase.csproj
- name: Upload Package
uses: actions/upload-artifact@v3
with:
name: database
path: MyDatabase/bin/Debug/net10.0/*.pgpac
What is .pgpac?
A .pgpac (PostgreSQL Data-tier Application Package) is:
- 📦 ZIP file containing your database schema
- 📄 Single
content.jsonfile inside - 🚀 Deployable with
postgresPacTools publish - ✅ Version controllable artifact
Deployment
After building, deploy with:
postgresPacTools publish \
-sf bin/Debug/net10.0/MyDatabase.pgpac \
-tcs "Host=server;Database=mydb;Username=user;Password=pass"
Comparison with MSBuild.Sdk.SqlProj
If you're familiar with SQL Server database projects:
| Feature | SQL Server | PostgreSQL (this SDK) |
|---|---|---|
| SDK | MSBuild.Sdk.SqlProj | MSBuild.Sdk.PostgreSql |
| Output | .dacpac |
.pgpac |
| SQL Discovery | ✅ Auto | ✅ Auto |
| MSBuild | ✅ | ✅ |
| Validation | ✅ | ✅ |
| Incremental | ✅ | ✅ |
Advanced Usage
Custom Output Path
<PropertyGroup>
<PgPacFilePath>$(MSBuildProjectDirectory)\dist\$(DatabaseName).pgpac</PgPacFilePath>
</PropertyGroup>
Use
PgPacFilePathto control the generated database package location. The SDK intentionally does not overrideTargetPath, so Visual Studio and the .NET project system can continue to treat the project like a normal SDK-style .NET project.
JSON Output
<PropertyGroup>
<OutputFormat>json</OutputFormat>
<PgPacFileName>$(DatabaseName).pgproj.json</PgPacFileName>
</PropertyGroup>
Disable Validation
<PropertyGroup>
<ValidateOnBuild>false</ValidateOnBuild>
</PropertyGroup>
Requirements
- .NET 10 SDK or later
- PostgreSQL database for deployment
Links
- GitHub: https://github.com/mbulava-org/pgPacTool
- NuGet: https://www.nuget.org/packages/MSBuild.Sdk.PostgreSql
- Documentation: https://github.com/mbulava-org/pgPacTool/tree/main/docs
License
MIT License - see LICENSE file
Contributing
Contributions welcome! See CONTRIBUTING.md
Build PostgreSQL databases like a pro! 🐘🚀
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
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 |
|---|---|---|
| 1.0.0 | 96 | 5/31/2026 |
| 1.0.0-preview9 | 94 | 5/18/2026 |
| 1.0.0-preview7 | 106 | 4/18/2026 |
| 1.0.0-preview6 | 101 | 4/14/2026 |
| 1.0.0-preview5 | 106 | 4/13/2026 |
| 1.0.0-preview4 | 103 | 4/12/2026 |
| 1.0.0-preview3 | 122 | 4/10/2026 |
| 1.0.0-preview2 | 109 | 4/9/2026 |
| 1.0.0-preview10 | 104 | 5/18/2026 |
| 1.0.0-preview1 | 120 | 3/18/2026 |