shanescott.sql-exporter 1.0.3

dotnet tool install --global shanescott.sql-exporter --version 1.0.3
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local shanescott.sql-exporter --version 1.0.3
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=shanescott.sql-exporter&version=1.0.3
                    
nuke :add-package shanescott.sql-exporter --version 1.0.3
                    

SqlExporter – Build Guide

This document explains how the SqlExporter tool was designed and built so future maintainers can understand and extend it.


🎯 Goal

We wanted a reusable command-line tool to:

  • Script tables, views, and stored procedures from SQL Server
  • Export them as .sql files into a project’s SQL folder
  • Work across multiple repos without duplicating code
  • Integrate smoothly into VS Code and CI/CD workflows

🛠️ Technology Choices

  • .NET 9 Console App
    Modern C# features, easy to distribute as a .NET tool.

  • SMO (SQL Server Management Objects)
    Provides reliable scripting of SQL Server objects, including indexes, constraints, and triggers.

  • Configuration System
    Supports JSON files (sqlexporter.json), environment variables, and CLI overrides.

  • .NET Tool Packaging
    Packaged as a NuGet .nupkg with <PackAsTool> for local or global installation.


⚙️ Core Components

Program.cs

  • Parses CLI options (--server, --database, --auth, etc.).
  • Loads configuration (JSON + env vars + CLI overrides).
  • Validates required fields.
  • Connects to SQL Server with Microsoft.Data.SqlClient.
  • Uses Scripter from SMO to export:
    • Tables → SQL/Tables
    • Views → SQL/Views
    • Stored Procedures → SQL/StoredProcedures
  • Writes UTF-8 .sql files with GO terminators.

ExportSettings.cs

A simple settings class:

class ExportSettings
{
    public string Server { get; set; }
    public string Database { get; set; }
    public string Auth { get; set; }
    public string User { get; set; }
    public string Password { get; set; }
    public bool Encrypt { get; set; } = true;
    public bool TrustServerCertificate { get; set; } = true;
    public string OutputRoot { get; set; } = "./SQL";
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.

This package has no dependencies.

Version Downloads Last Updated
1.0.3 244 10/7/2025
1.0.2 213 10/7/2025
1.0.1 289 9/19/2025