Fix packaging: zip first then rename, whitelist only plugin files

This commit is contained in:
2026-04-22 10:15:41 +10:00
parent a6080ab2d3
commit b7359a6857
+16 -26
View File
@@ -52,10 +52,6 @@ Write-Host "Using MSBuild: $msbuild" -ForegroundColor Gray
# --- Resolve all HintPaths to Disco bin --- # --- Resolve all HintPaths to Disco bin ---
$csproj = Join-Path $PluginDir "$PluginName.csproj" $csproj = Join-Path $PluginDir "$PluginName.csproj"
$csprojContent = Get-Content $csproj -Raw $csprojContent = Get-Content $csproj -Raw
# Replace ALL HintPath entries to point at DiscoBinPath
# This catches Disco.Models, Disco.Data, Disco.Services, Newtonsoft.Json,
# System.Web.Mvc, System.Web.WebPages, System.Web.Razor, etc.
$csprojContent = [regex]::Replace($csprojContent, '<HintPath>[^<]+\\([^\\<]+\.dll)</HintPath>', "<HintPath>$DiscoBinPath\`$1</HintPath>") $csprojContent = [regex]::Replace($csprojContent, '<HintPath>[^<]+\\([^\\<]+\.dll)</HintPath>', "<HintPath>$DiscoBinPath\`$1</HintPath>")
$tempCsproj = Join-Path $PluginDir "$PluginName.build.csproj" $tempCsproj = Join-Path $PluginDir "$PluginName.build.csproj"
@@ -85,7 +81,6 @@ Write-Host "Build successful: $pluginDll" -ForegroundColor Green
# --- Generate Manifest --- # --- Generate Manifest ---
Write-Host "`nGenerating manifest..." -ForegroundColor Yellow Write-Host "`nGenerating manifest..." -ForegroundColor Yellow
# Copy all DLLs from Disco bin to build output for ManifestGenerator
foreach ($dll in $requiredDlls) { foreach ($dll in $requiredDlls) {
Copy-Item (Join-Path $DiscoBinPath $dll) $buildOutput -Force -ErrorAction SilentlyContinue Copy-Item (Join-Path $DiscoBinPath $dll) $buildOutput -Force -ErrorAction SilentlyContinue
} }
@@ -95,7 +90,6 @@ foreach ($dep in $extraDlls) {
if (Test-Path $depPath) { Copy-Item $depPath $buildOutput -Force -ErrorAction SilentlyContinue } if (Test-Path $depPath) { Copy-Item $depPath $buildOutput -Force -ErrorAction SilentlyContinue }
} }
# Try ManifestGenerator
$useManifestGen = $false $useManifestGen = $false
$manifestGenExe = Join-Path $DiscoBinPath "Disco.Services.Plugins.ManifestGenerator.exe" $manifestGenExe = Join-Path $DiscoBinPath "Disco.Services.Plugins.ManifestGenerator.exe"
if (-not (Test-Path $manifestGenExe)) { if (-not (Test-Path $manifestGenExe)) {
@@ -131,12 +125,8 @@ if (-not $useManifestGen) {
# --- Package --- # --- Package ---
Write-Host "`nPackaging .discoPlugin file..." -ForegroundColor Yellow Write-Host "`nPackaging .discoPlugin file..." -ForegroundColor Yellow
$excludePatterns = @( # Only include the plugin DLL, PDB, and manifest - nothing else
"Disco.Models.*", "Disco.Data.*", "Disco.Services.*", "Disco.Web.*", "Disco.BI.*", $includeFiles = @("$PluginName.dll", "$PluginName.pdb", "manifest.json")
"EntityFramework.*", "System.Web.Mvc.*", "System.Web.WebPages.*", "System.Web.Razor.*",
"RazorGenerator.Mvc.*", "Newtonsoft.Json.*",
"*.build.csproj", "*.discoPlugin"
)
if (-not $version) { if (-not $version) {
$version = [System.Reflection.AssemblyName]::GetAssemblyName($pluginDll).Version $version = [System.Reflection.AssemblyName]::GetAssemblyName($pluginDll).Version
@@ -145,29 +135,29 @@ if (-not $version) {
$packageName = "$PluginName-$($version.ToString()).discoPlugin" $packageName = "$PluginName-$($version.ToString()).discoPlugin"
$packagePath = Join-Path $PluginDir $packageName $packagePath = Join-Path $PluginDir $packageName
# Clean old packages
Get-ChildItem $PluginDir -Filter "*.discoPlugin" | Remove-Item -Force Get-ChildItem $PluginDir -Filter "*.discoPlugin" | Remove-Item -Force
Get-ChildItem $PluginDir -Filter "*.zip" | Where-Object { $_.Name -like "$PluginName*" } | Remove-Item -Force
$filesToPackage = Get-ChildItem $buildOutput -Recurse -File | Where-Object { # Build clean temp folder with only plugin files
$file = $_.Name
-not ($excludePatterns | Where-Object { $file -like $_ })
}
$tempPkg = Join-Path $env:TEMP "discoplugin_$([guid]::NewGuid().ToString('N'))" $tempPkg = Join-Path $env:TEMP "discoplugin_$([guid]::NewGuid().ToString('N'))"
New-Item -ItemType Directory -Path $tempPkg -Force | Out-Null New-Item -ItemType Directory -Path $tempPkg -Force | Out-Null
foreach ($f in $filesToPackage) { foreach ($f in $includeFiles) {
$relativePath = $f.FullName.Substring($buildOutput.Length + 1) $src = Join-Path $buildOutput $f
$destPath = Join-Path $tempPkg $relativePath if (Test-Path $src) {
$destDir = Split-Path $destPath -Parent Copy-Item $src $tempPkg -Force
if (-not (Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null } }
Copy-Item $f.FullName $destPath -Force
} }
Write-Host "Files in package:" -ForegroundColor Gray Write-Host "Files in package:" -ForegroundColor Gray
Get-ChildItem $tempPkg -Recurse -File | ForEach-Object { Get-ChildItem $tempPkg -File | ForEach-Object {
Write-Host " $($_.FullName.Substring($tempPkg.Length + 1))" -ForegroundColor Gray Write-Host " $($_.Name)" -ForegroundColor Gray
} }
Compress-Archive -Path "$tempPkg\*" -DestinationPath $packagePath -Force # Create as .zip first (Compress-Archive requires .zip), then rename
$zipPath = Join-Path $PluginDir "$PluginName-$($version.ToString()).zip"
Compress-Archive -Path "$tempPkg\*" -DestinationPath $zipPath -Force
Rename-Item $zipPath $packageName -Force
Remove-Item $tempPkg -Recurse -Force Remove-Item $tempPkg -Recurse -Force
$packageSize = [math]::Round((Get-Item $packagePath).Length / 1KB, 1) $packageSize = [math]::Round((Get-Item $packagePath).Length / 1KB, 1)