MSBuild.Sdk.PostgreSql 1.0.0-preview1

This is a prerelease version of MSBuild.Sdk.PostgreSql.
There is a newer version of this package available.
See the version list below for details.
dotnet add package MSBuild.Sdk.PostgreSql --version 1.0.0-preview1
                    
NuGet\Install-Package MSBuild.Sdk.PostgreSql -Version 1.0.0-preview1
                    
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="MSBuild.Sdk.PostgreSql" Version="1.0.0-preview1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MSBuild.Sdk.PostgreSql" Version="1.0.0-preview1" />
                    
Directory.Packages.props
<PackageReference Include="MSBuild.Sdk.PostgreSql">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 MSBuild.Sdk.PostgreSql --version 1.0.0-preview1
                    
#r "nuget: MSBuild.Sdk.PostgreSql, 1.0.0-preview1"
                    
#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 MSBuild.Sdk.PostgreSql@1.0.0-preview1
                    
#: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=MSBuild.Sdk.PostgreSql&version=1.0.0-preview1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MSBuild.Sdk.PostgreSql&version=1.0.0-preview1&prerelease
                    
Install as a Cake Tool

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

1. Create a Database Project

<Project Sdk="MSBuild.Sdk.PostgreSql/1.0.0-preview1">

  <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

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
PgPacFileName {DatabaseName}.pgpac Output file name

Example

<Project Sdk="MSBuild.Sdk.PostgreSql/1.0.0-preview1">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <DatabaseName>ProductionDB</DatabaseName>
    <OutputFormat>pgpac</OutputFormat>
    <ValidateOnBuild>true</ValidateOnBuild>
  </PropertyGroup>

  
  <ItemGroup>
    <PreDeploy Include="Scripts\PreDeployment\BackupData.sql" />
    <PostDeploy Include="Scripts\PostDeployment\SeedData.sql" />
  </ItemGroup>

</Project>

Build Integration

dotnet CLI

# Build
dotnet build

# Clean
dotnet clean

# Rebuild
dotnet rebuild

Visual Studio

  • Open the .csproj in Visual Studio
  • Press Ctrl+Shift+B to build
  • Output appears in bin\Debug\net10.0\

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.json file 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>

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

License

MIT License - see LICENSE file

Contributing

Contributions welcome! See CONTRIBUTING.md


Build PostgreSQL databases like a pro! 🐘🚀

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
1.0.0 113 5/31/2026
1.0.0-preview9 108 5/18/2026
1.0.0-preview7 111 4/18/2026
1.0.0-preview6 113 4/14/2026
1.0.0-preview5 114 4/13/2026
1.0.0-preview4 110 4/12/2026
1.0.0-preview3 142 4/10/2026
1.0.0-preview2 116 4/9/2026
1.0.0-preview10 120 5/18/2026
1.0.0-preview1 130 3/18/2026