How brynjmsdlnn/addstoredprocedure works
What this project is (type + purpose)
This is not an application; it’s a NuGet Package Manager Console (PMC) helper package for Visual Studio / NuGet (classic packages.config workflow) that installs a PowerShell command: Add-StoredProcedure.
Purpose:
• Scaffold timestamped .sql stored procedure files into a target “Infrastructure” project.
• Auto-detect the Infrastructure project by presence of a Migrations folder.
• Automatically edits the target .csproj to include each generated .sql as an EmbeddedResource (grouped by schema/table, with a comment header).
• Runs inside Visual Studio’s PMC with support for -WhatIf, author detection, BOM-safe UTF-8 output, etc.
What the file tree implies about architecture
Top-level:
• AddStoredProcedure.nuspec: NuGet packaging manifest; defines package metadata and what goes into lib/ and tools/.
• tools/
• Add-StoredProcedure.ps1: the actual command implementation.
• init.ps1: NuGet “install-time” script that loads/registers the command into the PMC session.
• lib/net48/_._ and lib/net481/_._: compatibility shims so NuGet sees the package as compatible with those frameworks (there is no compiled assembly here).
• No src/, no compiled code, no tests—this is script-only shipped as a NuGet package.
Key architectural point: NuGet/Visual Studio PMC execution model is the runtime. The “host” is Visual Studio + NuGet Package Manager Console.
What the README adds (runtime behavior & interactions)
• Input: Add-StoredProcedure -Name -Schema -Table [-Author] [-Anon] [-WhatIf]
• Discovery: “Infrastructure project” detection by scanning solution projects for Migrations folder
• Output artifacts:
• File created at: Database\StoredProcedures\<schema>\<table>\<timestamp>_<name>.sql
• .csproj updated: <EmbeddedResource Include="...sql" /> plus grouping comment
• Environment integrations:
• Author detection chain: GitHub Actions → Azure DevOps → Git config → solution name fallback
• Uses Visual Studio DTE/PMC context (implied by common PMC scripting patterns and the troubleshooting note about $DTE)
NuGet Package: AddStoredProcedure
• Contains: tools/init.ps1, tools/Add-StoredProcedure.ps1, lib/*/_._, .nuspec
Host Environment
• Visual Studio
• NuGet Package Manager Console (PowerShell runspace)
Command Module
• Add-StoredProcedure PowerShell function/script (core logic)
Target Solution/Projects
• Infrastructure project (auto-detected by presence of Migrations/)
• Other projects (only relevant for discovery step)
Files / Artifacts in Infrastructure Project
• Database/StoredProcedures/.../*.sql
• *.csproj file (MSBuild XML) being modified
External/Environment Metadata Sources (for author detection)
• GitHub Actions env vars
• Azure DevOps env vars
• Local Git config
• Solution name fallback
• Developer → Visual Studio PMC: Install-Package AddStoredProcedure ...
• NuGet → executes tools/init.ps1
• init.ps1 → dot-sources / registers Add-StoredProcedure.ps1 into the PMC session
• Developer → PMC: runs Add-StoredProcedure -Name ...
• Add-StoredProcedure.ps1 → queries Visual Studio solution/projects context (DTE/PMC variables)
• Add-StoredProcedure.ps1 → scans projects → finds project containing Migrations/ (Infrastructure)
• Add-StoredProcedure.ps1 → reads env vars / git config → resolves Author
• Add-StoredProcedure.ps1 → writes .sql file to target folder path
• Add-StoredProcedure.ps1 → edits .csproj to add <EmbeddedResource Include="...">
• (Conditional branch) If -WhatIf: actions are simulated; no file system / csproj writes
Architectural patterns / principles
• Tooling automation pattern: “scripted scaffolding” integrated via NuGet tools/ scripts.
• Convention-over-configuration:
• Infrastructure project inferred by Migrations/ presence
• Output path conventions by schema/table
• Timestamp naming convention for ordering
• Idempotent-ish / safe operations: -WhatIf, BOM-safe UTF-8 output, comment-grouping in .csproj
• Host-coupled runtime: depends on Visual Studio PMC / DTE context (not a cross-platform CLI).
Relevant technologies explicitly (labels)
• PowerShell (PMC)
• Visual Studio + NuGet (packages.config-era tooling semantics)
• MSBuild .csproj editing
• .NET Framework compatibility (net481 target requirement, though no assemblies are shipped)
Runtime/Execution view (what happens when the command is run)
• Parameter parsing/validation (-Name, -Schema, -Table, -Author, -Anon, -WhatIf)
• Infrastructure project discovery (scan solution projects for Migrations/)
• Path computation (schema/table + timestamp prefix)
• SQL template renderer (header with author/date/object)
• Encoding writer (UTF-8, BOM-safe)
• .csproj updater (inserts comment group + EmbeddedResource Include=...)
• Dry-run executor (-WhatIf branch)