# Build-Plugin.ps1 # Builds and packages the AD Compare plugin for Disco ICT import # # Prerequisites: # - Visual Studio or MSBuild installed # - Disco solution built (for assembly references and ManifestGenerator) # # Usage: # .\Build-Plugin.ps1 -DiscoSolutionPath "C:\Path\To\Disco" param( [Parameter(Mandatory=$true)] [string]$DiscoSolutionPath, [string]$Configuration = "Release" ) $ErrorActionPreference = "Stop" $PluginDir = $PSScriptRoot $PluginName = "Disco.Plugins.ADCompare" Write-Host "=== AD Compare Plugin Builder ===" -ForegroundColor Cyan # --- Validate Disco solution path --- $discoServicesDir = Join-Path $DiscoSolutionPath "Disco.Services\bin\$Configuration" $discoModelsDir = Join-Path $DiscoSolutionPath "Disco.Models\bin\$Configuration" $discoDataDir = Join-Path $DiscoSolutionPath "Disco.Data\bin\$Configuration" $manifestGenDir = Join-Path $DiscoSolutionPath "Disco.Services.Plugins.ManifestGenerator\bin\$Configuration" $requiredDlls = @( (Join-Path $discoServicesDir "Disco.Services.dll"), (Join-Path $discoModelsDir "Disco.Models.dll"), (Join-Path $discoDataDir "Disco.Data.dll") ) foreach ($dll in $requiredDlls) { if (-not (Test-Path $dll)) { Write-Error "Required assembly not found: $dll`nMake sure the Disco solution is built first ($Configuration configuration)." exit 1 } } $manifestGenExe = Join-Path $manifestGenDir "Disco.Services.Plugins.ManifestGenerator.exe" if (-not (Test-Path $manifestGenExe)) { Write-Warning "ManifestGenerator not found at: $manifestGenExe" Write-Warning "Will create manifest.json manually instead." $useManifestGen = $false } else { $useManifestGen = $true } # --- Find MSBuild --- $msbuild = $null $vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" if (Test-Path $vsWhere) { $msbuild = & $vsWhere -latest -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\MSBuild.exe" | Select-Object -First 1 } if (-not $msbuild -or -not (Test-Path $msbuild)) { $msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" } if (-not (Test-Path $msbuild)) { Write-Error "MSBuild not found. Install Visual Studio or .NET Framework SDK." exit 1 } Write-Host "Using MSBuild: $msbuild" -ForegroundColor Gray # --- Update assembly references to point at actual Disco build --- $csproj = Join-Path $PluginDir "$PluginName.csproj" $csprojContent = Get-Content $csproj -Raw $csprojContent = $csprojContent -replace '\.\.\\Disco\.Models\\bin\\Debug\\Disco\.Models\.dll', "$($discoModelsDir)\Disco.Models.dll" $csprojContent = $csprojContent -replace '\.\.\\Disco\.Data\\bin\\Debug\\Disco\.Data\.dll', "$($discoDataDir)\Disco.Data.dll" $csprojContent = $csprojContent -replace '\.\.\\Disco\.Services\\bin\\Debug\\Disco\.Services\.dll', "$($discoServicesDir)\Disco.Services.dll" $newtonsoftPath = Get-ChildItem -Path $discoServicesDir -Filter "Newtonsoft.Json.dll" -ErrorAction SilentlyContinue | Select-Object -First 1 if ($newtonsoftPath) { $csprojContent = $csprojContent -replace '\.\.\\packages\\Newtonsoft\.Json[^<]+', "$($newtonsoftPath.FullName)" } $tempCsproj = Join-Path $PluginDir "$PluginName.build.csproj" $csprojContent | Set-Content $tempCsproj -Encoding UTF8 # --- Build --- Write-Host "`nBuilding $PluginName ($Configuration)..." -ForegroundColor Yellow $buildOutput = Join-Path $PluginDir "bin\$Configuration" & $msbuild $tempCsproj /p:Configuration=$Configuration /p:OutputPath=$buildOutput /t:Build /v:minimal if ($LASTEXITCODE -ne 0) { Remove-Item $tempCsproj -ErrorAction SilentlyContinue Write-Error "Build failed!" exit 1 } Remove-Item $tempCsproj -ErrorAction SilentlyContinue $pluginDll = Join-Path $buildOutput "$PluginName.dll" if (-not (Test-Path $pluginDll)) { Write-Error "Build output not found: $pluginDll" exit 1 } Write-Host "Build successful: $pluginDll" -ForegroundColor Green # --- Generate Manifest --- Write-Host "`nGenerating manifest..." -ForegroundColor Yellow foreach ($dll in $requiredDlls) { Copy-Item $dll $buildOutput -Force -ErrorAction SilentlyContinue } $depDlls = @("EntityFramework.dll", "System.Web.Mvc.dll", "RazorGenerator.Mvc.dll", "Newtonsoft.Json.dll") foreach ($dep in $depDlls) { $depPath = Join-Path $discoServicesDir $dep if (Test-Path $depPath) { Copy-Item $depPath $buildOutput -Force -ErrorAction SilentlyContinue } } if ($useManifestGen) { & $manifestGenExe $pluginDll if ($LASTEXITCODE -ne 0) { Write-Warning "ManifestGenerator failed, creating manifest manually..." $useManifestGen = $false } } if (-not $useManifestGen) { $version = [System.Reflection.AssemblyName]::GetAssemblyName($pluginDll).Version $manifest = @{ Id = $PluginName Name = "AD Compare" Author = "Jess" Url = "https://gitea.hideawaygaming.com.au/jessikitty/disco-ad-compare-plugin" Version = $version.ToString() AssemblyPath = "$PluginName.dll" TypeName = "Disco.Plugins.ADCompare.ADComparePlugin" ConfigurationHandlerTypeName = "Disco.Plugins.ADCompare.ConfigurationHandler.ADCompareConfigurationHandler" WebHandlerTypeName = "Disco.Plugins.ADCompare.WebHandler.ADCompareWebHandler" Features = @() } $manifest | ConvertTo-Json -Depth 5 | Set-Content (Join-Path $buildOutput "manifest.json") -Encoding UTF8 Write-Host "Manual manifest.json created" -ForegroundColor Green } # --- Package as .discoPlugin --- Write-Host "`nPackaging .discoPlugin file..." -ForegroundColor Yellow $excludePatterns = @( "Disco.Models.*", "Disco.Data.*", "Disco.Services.*", "Disco.Web.*", "Disco.BI.*", "EntityFramework.*", "System.Web.Mvc.*", "RazorGenerator.Mvc.*", "Newtonsoft.Json.*", "*.build.csproj", "*.discoPlugin" ) $packageName = "$PluginName-$($version.ToString()).discoPlugin" $packagePath = Join-Path $PluginDir $packageName Get-ChildItem $PluginDir -Filter "*.discoPlugin" | Remove-Item -Force $filesToPackage = Get-ChildItem $buildOutput -Recurse -File | Where-Object { $file = $_.Name -not ($excludePatterns | Where-Object { $file -like $_ }) } $tempPkg = Join-Path $env:TEMP "discoplugin_$([guid]::NewGuid().ToString('N'))" New-Item -ItemType Directory -Path $tempPkg -Force | Out-Null foreach ($f in $filesToPackage) { $relativePath = $f.FullName.Substring($buildOutput.Length + 1) $destPath = Join-Path $tempPkg $relativePath $destDir = Split-Path $destPath -Parent if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null } Copy-Item $f.FullName $destPath -Force } Compress-Archive -Path "$tempPkg\*" -DestinationPath $packagePath -Force Remove-Item $tempPkg -Recurse -Force Write-Host "`n=== Package created: $packagePath ===" -ForegroundColor Green Write-Host "Import this file into Disco ICT via: Configuration > Plugins > Install" -ForegroundColor Cyan