Skip to content

DevPossible/devpossible-pwsh-projecttemplate

Repository files navigation

DevPossible PowerShell Project Template

An MSBuild SDK and project template that enables PowerShell-driven builds for .NET solutions. Instead of compiling code, projects execute PowerShell scripts (build.ps1, clean.ps1, publish.ps1) with all MSBuild properties exposed as environment variables.

Features

  • Full MSBuild Integration - Works with dotnet build, msbuild, Visual Studio, and CI/CD pipelines
  • PowerShell Scripts - Complete control over build, clean, and publish processes
  • Environment Variables - All MSBuild properties exposed as MBLD_* variables
  • Standard Output Paths - Follows .NET conventions (bin/Debug/net8.0/)
  • Project Template - Quick start with dotnet new psproj

Quick Start

Install the Template

dotnet new install DevPossible.PwshProject.Templates

Create a New Project

dotnet new psproj -n MyProject
cd MyProject

Build

dotnet build           # Runs build.ps1
dotnet build -c Release
dotnet clean           # Runs clean.ps1
dotnet publish         # Runs publish.ps1

Project Structure

MyProject/
├── MyProject.psproj   # Project file (references the SDK)
├── build.ps1          # Build script - your build logic here
├── clean.ps1          # Clean script - cleanup logic
└── publish.ps1        # Publish script - deployment logic

How It Works

  1. Your .psproj file references DevPossible.PwshProject.Sdk
  2. When you run dotnet build, the SDK intercepts the Build target
  3. The SDK converts all MSBuild properties to MBLD_* environment variables
  4. Your build.ps1 script runs with full access to build context
  5. Same pattern for Clean and Publish targets

Environment Variables

Your scripts have access to all MSBuild properties via MBLD_* environment variables:

Variable Description Example
MBLD_PROJECT_DIR Project directory C:\src\MyProject
MBLD_PROJECT_NAME Project name MyProject
MBLD_CONFIGURATION Build configuration Debug or Release
MBLD_TARGET_FRAMEWORK Target framework net8.0
MBLD_OUT_DIR Output directory bin\Debug\net8.0\
MBLD_PUBLISH_DIR Publish directory bin\publish\Release\
MBLD_VERSION Version number 1.0.0
... And 25+ more!

Example build.ps1

#Requires -Version 7.0
$ErrorActionPreference = 'Stop'

Write-Host "Building $env:MBLD_PROJECT_NAME ($env:MBLD_CONFIGURATION)..."

# Ensure output directory exists
if (-not (Test-Path $env:MBLD_OUT_DIR)) {
    New-Item -ItemType Directory -Path $env:MBLD_OUT_DIR -Force | Out-Null
}

# Your build logic here - examples:
# - Compile TypeScript: npx tsc --outDir $env:MBLD_OUT_DIR
# - Bundle JavaScript: npx webpack --mode production
# - Process templates: Copy-Item ./src/* $env:MBLD_OUT_DIR
# - Generate docs: docfx build

Write-Host "Build complete!"

Use Cases

  • TypeScript/JavaScript - Compile and bundle frontend code
  • Static Sites - Generate Hugo, Jekyll, or custom static sites
  • Asset Processing - Optimize images, compile SASS
  • Multi-Step Pipelines - Complex build workflows
  • Custom Deployments - Package and deploy applications
  • Documentation - Generate and publish docs

Configuration

Override SDK defaults in your project file:

<Project Sdk="DevPossible.PwshProject.Sdk/1.0.0">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>

    <!-- Custom script names -->
    <PwshBuildScript>my-build.ps1</PwshBuildScript>

    <!-- Disable specific targets -->
    <PwshCleanEnabled>false</PwshCleanEnabled>

    <!-- Custom PowerShell executable -->
    <PwshExecutable>pwsh.exe</PwshExecutable>
  </PropertyGroup>
</Project>

Packages

Package Description NuGet
DevPossible.PwshProject.Sdk MSBuild SDK NuGet
DevPossible.PwshProject.Templates Project template NuGet

Requirements

  • .NET SDK 8.0 or later
  • PowerShell 7.0 or later

Building from Source

# Clone the repository
git clone https://github.com/devpossible/devpossible-pwsh-projecttemplate.git
cd devpossible-pwsh-projecttemplate

# Run smoke tests
./test-smoke.ps1

# Build packages
./build.ps1 -Configuration Release

# Packages are created in .dist/

Related Projects

License

MIT

About

MSBuild SDK and project template for PowerShell-driven builds. Execute build.ps1, clean.ps1, and publish.ps1 scripts instead of compiling code.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors