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
                    
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">
  <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" />
                    
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
                    
#r "nuget: MSBuild.Sdk.PostgreSql, 1.0.0"
                    
#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
                    
#: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
                    
Install as a Cake Addin
#tool nuget:?package=MSBuild.Sdk.PostgreSql&version=1.0.0
                    
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

Before You Start

  • There is no separate Visual Studio project template installer for preview8.
  • Create the .csproj manually or generate one with pgpac extract.
  • To open the project in Visual Studio, make sure the solution can restore MSBuild.Sdk.PostgreSql from nuget.org or 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 .csproj directly or add it to an existing solution
  • If you are testing a local packed SDK, add a nuget.config with your local feed before opening the project
  • Run dotnet restore if Visual Studio reports the SDK cannot be resolved
  • Press Ctrl+Shift+B to build
  • Output appears in bin\Debug\net10.0\
  • Set PgPacToolVerbose=true in the project or pass it as an MSBuild property when you need the build to show verbose pgpac compile diagnostics

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

Use PgPacFilePath to control the generated database package location. The SDK intentionally does not override TargetPath, 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

License

MIT License - see LICENSE file

Contributing

Contributions welcome! See CONTRIBUTING.md


Build PostgreSQL databases like a pro! 🐘🚀

There are no supported framework assets in this package.

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