|
| 1 | +param( |
| 2 | + [switch]$IncludeDesktop |
| 3 | +) |
| 4 | +# Fast dev build for migration testing. |
| 5 | +# Produces a loadable module at artifacts/dbatools.library/ with the freshly built dbatools.dll. |
| 6 | +# Usage: |
| 7 | +# pwsh -NoProfile -File build/build-dev.ps1 |
| 8 | +# pwsh -NoProfile -Command 'Import-Module artifacts/dbatools.library/dbatools.library.psd1 -Force' |
| 9 | + |
| 10 | +$ErrorActionPreference = "Stop" |
| 11 | +$ProgressPreference = "SilentlyContinue" |
| 12 | + |
| 13 | +$root = Split-Path -Path $PSScriptRoot |
| 14 | +Push-Location $root |
| 15 | + |
| 16 | +try { |
| 17 | + $artifactsDir = Join-Path $root "artifacts" |
| 18 | + $moduleDir = Join-Path $artifactsDir "dbatools.library" |
| 19 | + $coreLibDir = Join-Path $moduleDir "core/lib" |
| 20 | + $tempPublish = Join-Path $artifactsDir "publish-temp" |
| 21 | + |
| 22 | + # Clean previous artifacts |
| 23 | + if (Test-Path $artifactsDir) { |
| 24 | + Remove-Item -Path $artifactsDir -Recurse -Force -ErrorAction SilentlyContinue |
| 25 | + } |
| 26 | + |
| 27 | + $null = New-Item -ItemType Directory -Path $moduleDir -Force |
| 28 | + $null = New-Item -ItemType Directory -Path $coreLibDir -Force |
| 29 | + $null = New-Item -ItemType Directory -Path $tempPublish -Force |
| 30 | + |
| 31 | + # Build and publish net8.0 (includes all dependency DLLs) |
| 32 | + Write-Host "Building net8.0..." -ForegroundColor Cyan |
| 33 | + dotnet publish project/dbatools/dbatools.csproj --configuration Debug --framework net8.0 --output $tempPublish --nologo --self-contained true 2>&1 | Out-Null |
| 34 | + if ($LASTEXITCODE -ne 0) { |
| 35 | + Write-Host "Build failed." -ForegroundColor Red |
| 36 | + exit 1 |
| 37 | + } |
| 38 | + |
| 39 | + # Copy all publish output to core/lib |
| 40 | + Copy-Item -Path "$tempPublish\*" -Destination $coreLibDir -Recurse -Force |
| 41 | + |
| 42 | + # SqlClient: the publish output has a Windows version but psm1 expects the unix one for net8.0 |
| 43 | + # Copy the unix SqlClient over the Windows one (matches what build.ps1 does) |
| 44 | + $unixSqlClient = Join-Path $coreLibDir "runtimes/unix/lib/net8.0/Microsoft.Data.SqlClient.dll" |
| 45 | + if (Test-Path $unixSqlClient) { |
| 46 | + Copy-Item $unixSqlClient -Destination $coreLibDir -Force |
| 47 | + } |
| 48 | + |
| 49 | + # Create third-party/bogus directory (psm1 tries to load Bogus.dll) |
| 50 | + $bogusDir = Join-Path $moduleDir "core/third-party/bogus" |
| 51 | + $null = New-Item -ItemType Directory -Path $bogusDir -Force |
| 52 | + |
| 53 | + # Try to find Bogus.dll from the installed module |
| 54 | + $installedBogus = "C:\Program Files\PowerShell\Modules\dbatools.library\*\core\third-party\bogus\Bogus.dll" |
| 55 | + $bogusSource = Get-Item $installedBogus -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 56 | + if ($bogusSource) { |
| 57 | + Copy-Item $bogusSource.FullName -Destination $bogusDir -Force |
| 58 | + } else { |
| 59 | + Write-Host "Warning: Bogus.dll not found, module may show a non-fatal error on load" -ForegroundColor Yellow |
| 60 | + } |
| 61 | + |
| 62 | + # Copy module manifest and loader |
| 63 | + Copy-Item -Path (Join-Path $root "dbatools.library.psd1") -Destination $moduleDir -Force |
| 64 | + Copy-Item -Path (Join-Path $root "dbatools.library.psm1") -Destination $moduleDir -Force |
| 65 | + |
| 66 | + # Desktop build (optional, only needed for Windows PowerShell 5.1 testing) |
| 67 | + if ($IncludeDesktop) { |
| 68 | + $desktopLibDir = Join-Path $moduleDir "desktop/lib" |
| 69 | + $tempDesktop = Join-Path $artifactsDir "publish-temp-desktop" |
| 70 | + $null = New-Item -ItemType Directory -Path $desktopLibDir -Force |
| 71 | + $null = New-Item -ItemType Directory -Path $tempDesktop -Force |
| 72 | + |
| 73 | + Write-Host "Building net472..." -ForegroundColor Cyan |
| 74 | + dotnet publish project/dbatools/dbatools.csproj --configuration Debug --framework net472 --output $tempDesktop --nologo --self-contained true 2>&1 | Out-Null |
| 75 | + if ($LASTEXITCODE -ne 0) { |
| 76 | + Write-Host "Desktop build failed." -ForegroundColor Red |
| 77 | + exit 1 |
| 78 | + } |
| 79 | + Copy-Item -Path "$tempDesktop\*" -Destination $desktopLibDir -Recurse -Force |
| 80 | + } |
| 81 | + |
| 82 | + # Clean up temp |
| 83 | + Remove-Item -Path $tempPublish -Recurse -Force -ErrorAction SilentlyContinue |
| 84 | + if ($IncludeDesktop) { |
| 85 | + Remove-Item -Path (Join-Path $artifactsDir "publish-temp-desktop") -Recurse -Force -ErrorAction SilentlyContinue |
| 86 | + } |
| 87 | + |
| 88 | + Write-Host "Dev build complete: $moduleDir" -ForegroundColor Green |
| 89 | + Write-Host "Load with: Import-Module $moduleDir\dbatools.library.psd1 -Force" -ForegroundColor Green |
| 90 | +} finally { |
| 91 | + Pop-Location |
| 92 | +} |
0 commit comments