This document describes how to build and package the Posh-SSH module for distribution.
- Visual Studio 2019 or 2022 (Community, Professional, or Enterprise) OR Visual Studio Build Tools
- PowerShell 5.1 or PowerShell 7.x
- .NET Framework 4.7.2 SDK (for .NET Framework build)
- .NET Core SDK 2.0+ (for .NET Standard 2.0 build)
The repository includes an automated build script: Build-Module.ps1
Build and package the module:
.\Build-Module.ps1This will:
- Compile the C# binary module (PoshSSH.dll) from source
- Copy the netstandard2.0 version to the module directory
- Test that the module loads correctly
- Create a distribution ZIP file:
Posh-SSH-{version}.zip
.\Build-Module.ps1 -Configuration Debug.\Build-Module.ps1 -SkipBuild.\Build-Module.ps1 -SkipTests.\Build-Module.ps1 -OutputPath "C:\Releases".\Build-Module.ps1 -Configuration Release -OutputPath "C:\Releases" -SkipTestsThe build script produces:
- Compiled Binary:
Posh-SSH/PoshSSH.dll(netstandard2.0) - Distribution Package:
Posh-SSH-{version}.zip
The ZIP file contains:
- Complete module ready for installation
- All required assemblies and dependencies
- Documentation (README.md, License.md, CHANGELOG.md)
- NO source code - only the distributable module
Posh-SSH-3.2.6.zip
├── CHANGELOG.md
├── License.md
├── README.md
└── Posh-SSH/
├── Posh-SSH.psd1 # Module manifest
├── Posh-SSH.psm1 # PowerShell module
├── PoshSSH.dll # Binary cmdlets (netstandard2.0)
├── Add-SshIdentity.ps1 # Helper script
├── Assembly/ # Dependencies
│ ├── BouncyCastle.Cryptography.dll
│ ├── Renci.SshNet.dll
│ └── ... (other dependencies)
├── en-US/ # Help files
└── Format/ # Format definitions
If you need to build manually without using the script:
# Navigate to source directory
cd Source\PoshSSH
# Build using MSBuild (adjust path to your MSBuild installation)
& "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe" `
PoshSSH.sln /p:Configuration=Release /t:Clean,BuildIMPORTANT: Use the netstandard2.0 version, not the .NET Framework version!
# Copy the netstandard2.0 DLL to the module directory
Copy-Item -Path "Source\PoshSSH\PoshSSH.Core\bin\Release\netstandard2.0\PoshSSH.dll" `
-Destination "Posh-SSH\PoshSSH.dll" `
-Force# Remove any loaded version
Remove-Module Posh-SSH -ErrorAction SilentlyContinue
# Import the module
Import-Module .\Posh-SSH\Posh-SSH.psd1 -Force
# Verify it loaded
Get-Module Posh-SSH
Get-Command -Module Posh-SSH# Create a clean copy for distribution
$tempDir = New-Item -ItemType Directory -Path "$env:TEMP\Posh-SSH-Package" -Force
# Copy module files (no source code)
Copy-Item -Path "Posh-SSH\*" -Destination "$tempDir\Posh-SSH" -Recurse -Exclude "*.pdb"
Copy-Item -Path "README.md", "License.md", "CHANGELOG.md" -Destination $tempDir
# Create ZIP
$version = (Import-PowerShellDataFile "Posh-SSH\Posh-SSH.psd1").ModuleVersion
Compress-Archive -Path "$tempDir\*" -DestinationPath "Posh-SSH-$version.zip" -Force
# Cleanup
Remove-Item $tempDir -Recurse -ForceTo update the version number:
- Edit
Posh-SSH/Posh-SSH.psd1 - Update the
ModuleVersionfield:ModuleVersion = '3.2.7'
- Update
CHANGELOG.mdwith version notes - Run the build script
- Create a git tag:
git tag -a v3.2.7 -m "Version 3.2.7"
If the build script cannot find MSBuild:
- Install Visual Studio or Visual Studio Build Tools
- Ensure MSBuild is in one of the default locations, or
- Manually specify the path by editing the
Find-MSBuildfunction inBuild-Module.ps1
Always verify you're using the netstandard2.0 version:
# Check DLL size (netstandard2.0 should be ~46 KB)
Get-Item Posh-SSH\PoshSSH.dll | Select-Object Length, LastWriteTime
# Verify it loads
Import-Module .\Posh-SSH\Posh-SSH.psd1 -Force
Get-Command New-SSHSession | Select-Object DLLYou may see a warning about Newtonsoft.Json when building the .NET Framework version. This is expected and can be ignored - the module uses the version from the Assembly folder.
The build script is designed to work in CI/CD pipelines:
# Example GitHub Actions
- name: Build Posh-SSH
shell: pwsh
run: |
.\Build-Module.ps1 -SkipTests
- name: Upload Package
uses: actions/upload-artifact@v2
with:
name: Posh-SSH-Package
path: Posh-SSH-*.zip- Source Code:
Source/PoshSSH/- C# cmdlet implementations - Tests:
tests/- Pester unit and integration tests - Documentation:
docs/- Command documentation (Markdown) - Module:
Posh-SSH/- Distributable module directory