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
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
nuke :add-package shanescott.sql-exporter --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
.sqlfiles into a project’sSQLfolder - 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.nupkgwith<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
Scripterfrom SMO to export:- Tables →
SQL/Tables - Views →
SQL/Views - Stored Procedures →
SQL/StoredProcedures
- Tables →
- Writes UTF-8
.sqlfiles withGOterminators.
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 | Versions 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.