Build & Packaging Execution
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Build and Packaging Execution refers to the systematic process of compiling PowerShell source code and bundling the resulting binaries into platform-specific distribution formats such as MSI, DEB, RPM, and TAR. This system ensures that PowerShell is consistently built for multiple operating systems (Windows, Linux, macOS) and architectures (x64, x86, ARM, ARM64) while maintaining compliance through Software Bill of Materials (SBOM) validation.
Sources: README.md:10-15, test/perf/benchmarks/assets/compiler.test.ps1:1003-1015
Build Lifecycle Management
The build process is managed primarily through the Start-PSBuild and Start-PSPackage orchestration functions. These functions handle environment detection, dependency restoration, compilation via the .NET SDK, and post-processing tasks like CrossGen (Ahead-of-Time compilation).
Environment Detection and Bootstrap
Before a build begins, the system identifies the host operating system and architecture to determine valid target RIDs (Runtime Identifiers). The Get-EnvInformation function detects specific Linux distributions (Debian, Ubuntu, CentOS, Fedora, etc.) and macOS package managers (Homebrew or MacPorts).
Compilation Logic
The core build logic utilizes the dotnet publish command with specific properties tailored for PowerShell's unique requirements.
| Parameter | Function |
|---|---|
SMAOnly | Rebuilds only the System.Management.Automation.dll engine for rapid development. |
Runtime | Target RID (e.g., win7-x64, linux-arm64, osx-x64). |
Configuration | Build flavor: Debug, Release, or CodeCoverage. |
CrossGen | Enables ReadyToRun (R2R) optimization for non-fxdependent builds. |
Sources: test/perf/benchmarks/assets/compiler.test.ps1:105-155, test/perf/benchmarks/assets/compiler.test.ps1:225-250
Packaging and Distribution
Packaging transforms build artifacts into installable formats. The Start-PSPackage function coordinates the creation of various archive and installer types.
Manifest Generation
A critical step in packaging is the creation of the module manifest (.psd1). This is handled by the New-ModuleManifest cmdlet, which defines module metadata, exported members, and version requirements.
Package Types and Formats
PowerShell supports a wide range of distribution formats depending on the target environment:
- Linux: DEB (Debian/Ubuntu), RPM (RHEL/CentOS), and TAR.GZ.
- Windows: MSI, MSIX, and ZIP (including symbol-only ZIPs).
- macOS: PKG and TAR.GZ.
- Agnostic:
fxdependentandfxdependent-win-desktop(framework-dependent packages).
Sources: test/perf/benchmarks/assets/compiler.test.ps1:1003-1015, test/packaging/linux/package-validation.tests.ps1:10-20
Package Validation
Automated tests validate the naming conventions and structural integrity of generated packages. Regex patterns ensure that version strings, architectures, and release tags (LTS, Preview) are correctly embedded in the filenames.
| Package Type | Regex Pattern Component (Example) |
|---|---|
| RPM | powershell-(preview|lts-)?\d+\.\d+\.\d+-1\.(rh|cm)\.(x86_64|aarch64).rpm |
| DEB | ^powershell(-preview|-lts)?_\d+\.\d+\.\d+-1\.deb_(amd64|arm64)\.deb$ |
Sources: test/packaging/linux/package-validation.tests.ps1:24-35, test/packaging/linux/package-validation.tests.ps1:55-65
Security and Compliance
The build system incorporates security checks and compliance documentation into the final artifacts.
SBOM Verification
Software Bill of Materials (SBOM) are generated for every non-symbol package. The system verifies that a manifest.spdx.json exists within the _manifest/spdx_2.2/ directory of the archive and performs hash validation against the included files to ensure no tampering occurred post-build.
Sources: tools/packaging/releaseTests/sbom.tests.ps1:30-45, tools/packaging/releaseTests/sbom.tests.ps1:55-70
Digital Signatures and Notices
For Windows distributions, the packaging process requires copying ThirdPartyNotices.txt and default.help.txt into the staging directory to ensure legal compliance and offline help availability. Symbol packages specifically include psoptions.json and a symbols.zip containing PDB files for debugging.
Sources: test/perf/benchmarks/assets/compiler.test.ps1:1088-1115
Conclusion
Build & Packaging Execution in PowerShell is a high-complexity workflow that abstracts the differences between platforms through a unified set of PowerShell-based build scripts. By combining .NET's native compilation capabilities with custom validation logic for SBOMs and package naming, the project maintains a stable and secure delivery pipeline across disparate operating systems.