Requires PowerShell 5.1+ with the Sampler, ModuleBuilder, and InvokeBuild modules.
description
Reference for the Sampler PowerShell module build framework: project structure, build.yaml, dependency management, build workflows and tasks, custom build tasks, testing patterns, GitVersion versioning, CI/CD pipelines (Azure Pipelines, GitHub Actions), DSC/Datum configuration data projects, VSCode integration, multi-module repositories, community files, troubleshooting, and command reference. USE FOR: Sampler, build.yaml, RequiredModules.psd1, Resolve-Dependency, ModuleBuilder, InvokeBuild, New-SampleModule, Add-Sample, Sampler project structure, PowerShell module build, GitVersion configuration, CI/CD pipeline, Azure Pipelines PowerShell, DSC Datum, DscWorkshop, Sampler.DscPipeline, custom build task, Pester configuration, code coverage threshold, NuGet, Publish-Module, PowerShell Gallery, Set-SamplerTaskVariable, multi-module repository, patched module. DO NOT USE FOR: debugging Sampler builds (sampler-build-debug), legacy migration (sampler-migration), Pester syntax, AutomatedLab.
Sampler PowerShell Module Build Framework
Comprehensive reference for the Sampler build framework.
Sampler provides scaffolding, build automation, testing, versioning, and CI/CD pipeline
integration using ModuleBuilder, InvokeBuild, Pester 5, and GitVersion.
Note: For enforced coding rules that auto-apply when editing Sampler build files,
see sampler.instructions.md. For debugging build failures, see the sampler-build-debug
skill. For migrating legacy modules, see the sampler-migration skill.
Overview
Sampler serves several purposes:
Scaffold a PowerShell module project with consistent structure and practices
Build modules using ModuleBuilder and InvokeBuild tasks
Test with Pester 5 (unit, integration, and quality assurance tests)
Version automatically via GitVersion (semantic versioning from git history)
Package as NuGet packages for PowerShell Gallery publication
Deploy through Azure Pipelines or GitHub Actions CI/CD
Works cross-platform on Windows, Linux, and macOS
Assumes nothing about the local environment (no admin rights required)
Use one line as the inner command of the detached build wrapper, with its
working directory set to C:\source\MyModule:
# Resolve dependencies and build (first run)
./build.ps1 -ResolveDependency -Tasks build
# Resolve dependencies and run full default workflow (build + test)
./build.ps1 -ResolveDependency
Project Structure
Standard Sampler folder layout (source/, tests/, output/, RequiredModules.psd1, build.yaml, build.ps1) and what each path is for — read references/project-structure.md.
Module Manifest Conventions
Conventions for .psd1 manifests under Sampler — ModuleVersion placeholder, FunctionsToExport, PrivateData.PSData, and how ModuleBuilder merges them — read references/module-manifest.md.
Build Configuration (build.yaml)
Full build.yaml schema, every key, code-coverage thresholds, file copy patterns, and worked examples — read references/build-yaml.md.
Dependency Management (RequiredModules.psd1)
RequiredModules.psd1 schema, version-pinning patterns, gallery vs local sources, and dependency-resolution configuration — read references/dependency-management.md.
Use this as the inner command of the detached build wrapper:
# List all available tasks (dependencies must be resolved first)
./build.ps1 -Tasks ?
Custom Build Tasks
Writing custom InvokeBuild tasks, Set-SamplerTaskVariable pattern, task dependencies, and integration with the default workflow — read references/custom-build-tasks.md.
Testing Patterns
Pester 5 test scaffolding, Unit/Integration/QA folder conventions, code coverage configuration, mock patterns, and parametrised test recipes — read references/testing-patterns.md.
Versioning with GitVersion
GitVersion.yml configuration, branch strategies, version source override, and ModuleVersion injection during build — read references/gitversion.md.
CI/CD Integration
Azure Pipelines and GitHub Actions templates, build/test/publish stage layout, artefact handling, and gallery publishing — read references/ci-cd-pipelines.md.
Adding Code Samples with Add-Sample
Use Add-Sample to add scaffolded elements to an existing project:
# Add a public function with unit test
Add-Sample -Sample PublicFunction -PublicFunctionName Get-MyWidget
# Add a private function
Add-Sample -Sample PrivateFunction -PrivateFunctionName ConvertTo-InternalFormat
# Add a class
Add-Sample -Sample ClassResource -ResourceName MyResource
This creates the source file in the appropriate directory and a matching test file.
Multi-Module Repositories
Patterns for repositories that build multiple modules from one Sampler tree — read references/multi-module.md.
DSC and Datum Configuration Data Projects
DscWorkshop/Sampler.DscPipeline structure, Datum hierarchy and merge strategies, role composition, MOF compilation pipeline, and reference-implementation walkthrough — read references/dsc-datum.md.
VSCode Integration
VS Code tasks.json/launch.json templates, PowerShell extension settings, debugger configuration, and recommended extensions for Sampler projects — read references/vscode-integration.md.
Common Pitfalls and Troubleshooting
Build failures, dependency resolution errors, version mismatch symptoms, GitVersion edge cases, and known Sampler bugs with workarounds — read references/troubleshooting.md.
These variables influence build task behavior. Set via command line, environment variable, parent scope, or build.yaml.
Variable
Default
Description
OutputDirectory
output
Base directory for all build output
BuiltModuleSubdirectory
(empty)
Subdirectory under OutputDirectory for built module
BuildModuleOutput
OutputDirectory + BuiltModuleSubdirectory
Full path where module is built
ModuleVersion
GitVersion NuGetVersionV2
Module version for the build
ProjectPath
$BuildRoot
Root path of the project
ProjectName
Module manifest BaseName
Project/module name
SourcePath
Auto-detected
Path to source/ or src/ folder
ReleaseNotesPath
OutputDirectory/ReleaseNotes.md
Path to release notes output
Sampler Commands Reference
Full reference for New-SampleModule, Add-Sample, Set-SamplerTaskVariable, Invoke-SamplerTask, and other Sampler cmdlets — read references/commands-reference.md.
Summary Checklist
Use this checklist when creating or auditing a Sampler-based project:
Standard Module Projects
Project scaffolded with New-SampleModule or equivalent structure
Source code in source/Public/ and source/Private/ (one function per file)
Module manifest at source/<ModuleName>.psd1 with explicit exports
Empty source/<ModuleName>.psm1 placeholder
build.ps1 and Resolve-Dependency.* present (standard, unmodified)
build.yaml configured with correct workflows and Pester Script key
RequiredModules.psd1 lists all build and runtime dependencies
GitVersion.yml configured for your branching strategy
ModuleBuildTasks includes both Sampler and Sampler.GitHubTasks
Tests in tests/QA/, tests/Unit/, and optionally tests/Integration/
Tests use Pester 5 syntax with BeforeAll/BeforeDiscovery separation
CI/CD pipeline with Build, Test (multi-edition), and Deploy stages
Agent.Source.Git.ShallowFetchDepth: 0 in CI configuration