A Package Manager Console (PMC) helper that scaffolds timestamped SQL stored procedure files directly into your Infrastructure project — with automatic .csproj registration as EmbeddedResource.
- EF-style timestamp prefix (
yyyyMMddHHmmss) for ordered file naming - Auto-detects the Infrastructure project by looking for a
Migrationsfolder - Registers the generated
.sqlfile asEmbeddedResourcein your.csproj, grouped by schema/module with a comment header - Smart author detection: GitHub Actions → Azure DevOps → Git config → solution name fallback
- BOM-safe UTF-8 output
- Supports
-WhatIf
- Visual Studio with Package Manager Console
- .NET Framework 4.8.1 project (targets
net481) - A project in your solution that contains a
Migrationsfolder (Infrastructure project)
In Package Manager Console:
Install-Package AddStoredProcedure -ProjectName YourSolution.InfrastructureInstall-Package AddStoredProcedure -Version 1.0.11 `
-ProjectName YourSolution.Infrastructure `
-Source "C:\path\to\nuget\AddStoredProcedure\artifacts"After installation, you should see:
Add-StoredProcedure command loaded. Use: Add-StoredProcedure -Help
Add-StoredProcedure -Name <string> -Schema <string> -Table <string> [-Author <string>] [-Anon]| Parameter | Required | Description |
|---|---|---|
-Name |
Yes | Name of the stored procedure |
-Schema |
Yes | Database schema (e.g. dbo, Admin) |
-Table |
Yes | Logical subfolder grouping by table. |
-Author |
No | Explicit author name. Overrides auto-detection |
-Anon |
No | Forces author to the solution name |
-Help |
No | Displays usage information |
Basic usage:
Add-StoredProcedure -Name "usp_Users_GetAll" -Schema "dbo" -Table "Users"With an explicit author:
Add-StoredProcedure -Name "usp_Roles_GetAll" -Schema "dbo" -Table "Roles" -Author "John Doe"Preview without creating files (-WhatIf):
Add-StoredProcedure -Name "usp_Roles_GetAll" -Schema "dbo" -Table "Roles" -WhatIfRunning the command generates a .sql file under your Infrastructure project:
Database\
StoredProcedures\
dbo\
Users\
20260226150000_usp_Users_GetAll.sql
And registers it in your .csproj as:
<!-- Stored Procedures - dbo/Users -->
<EmbeddedResource Include="Database\StoredProcedures\dbo\Users\20260226150000_usp_Users_GetAll.sql" />-- =============================================
-- Author: John Doe
-- Object: StoredProcedure [dbo].[usp_Users_GetAll]
-- Script date: 02/26/2026
-- Description:
-- =============================================
CREATE OR ALTER PROCEDURE [dbo].[usp_Users_GetAll]
AS
BEGIN
SET NOCOUNT ON;
-- TODO: Add procedure logic
ENDnuget.exeon your PATH or in the package folder
AddStoredProcedure\
AddStoredProcedure.nuspec
lib\
net481\
_._
tools\
init.ps1
Add-StoredProcedure.ps1
artifacts\
In a terminal, navigate to the package folder and run:
.\nuget pack AddStoredProcedure.nuspec -OutputDirectory artifacts -NoDefaultExcludes.\nuget push "artifacts\AddStoredProcedure.1.0.11.nupkg" `
-ApiKey YOUR_API_KEY `
-Source https://api.nuget.org/v3/index.jsonGet your API key from https://www.nuget.org/account/apikeys
.\nuget delete AddStoredProcedure 1.0.11 `
-ApiKey YOUR_API_KEY `
-Source https://api.nuget.org/v3/index.jsonUnlisting hides the package from search but does not delete it. Existing installs and direct version references still work.
The init.ps1 did not run. This can happen on upgrades. Fix:
Uninstall-Package AddStoredProcedure -ProjectName YourSolution.Infrastructure
Install-Package AddStoredProcedure -Version 1.0.11 -ProjectName YourSolution.InfrastructureIf the error persists, manually dot-source the function:
. "C:\path\to\packages\AddStoredProcedure.1.0.11\tools\Add-StoredProcedure.ps1"You are running an older version of the script (1.0.6 or earlier) that is still loaded in memory from a previous session. Reload the correct version:
. "C:\path\to\packages\AddStoredProcedure.1.0.11\tools\Add-StoredProcedure.ps1"Your package is missing the lib\net481\_._ compatibility shim. Make sure the file exists on disk:
New-Item -ItemType Directory -Path "lib\net481" -Force
New-Item -Path "lib\net481\_._" -ItemType File -ForceThen rebuild and reinstall.
Manually clean up:
- Close Visual Studio
- Delete the package folder:
Remove-Item "C:\path\to\packages\AddStoredProcedure.1.0.x" -Recurse -Force
- Remove the entry from
packages.config:<package id="AddStoredProcedure" version="1.0.x" targetFramework="net481" />
- Remove any related
<Import>line from your.csproj - Reopen Visual Studio
PMC executed init.ps1 in a child scope. Dot-source manually as a workaround:
. "C:\path\to\packages\AddStoredProcedure.1.0.11\tools\Add-StoredProcedure.ps1"brynjmsdlnn