Simplify HintPath resolution - regex replaces ALL paths to Disco bin
This commit is contained in:
+20
-55
@@ -3,9 +3,6 @@
|
|||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# .\Build-Plugin.ps1 -DiscoBinPath "C:\Program Files\Disco\WebApp\bin"
|
# .\Build-Plugin.ps1 -DiscoBinPath "C:\Program Files\Disco\WebApp\bin"
|
||||||
#
|
|
||||||
# Or if you have the Disco source solution built:
|
|
||||||
# .\Build-Plugin.ps1 -DiscoBinPath "C:\Source\Disco\Disco.Web\bin"
|
|
||||||
|
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
@@ -21,7 +18,7 @@ $PluginName = "Disco.Plugins.ADCompare"
|
|||||||
Write-Host "=== AD Compare Plugin Builder ===" -ForegroundColor Cyan
|
Write-Host "=== AD Compare Plugin Builder ===" -ForegroundColor Cyan
|
||||||
Write-Host "Disco bin path: $DiscoBinPath" -ForegroundColor Gray
|
Write-Host "Disco bin path: $DiscoBinPath" -ForegroundColor Gray
|
||||||
|
|
||||||
# --- Validate Disco bin path and required DLLs ---
|
# --- Validate ---
|
||||||
if (-not (Test-Path $DiscoBinPath)) {
|
if (-not (Test-Path $DiscoBinPath)) {
|
||||||
Write-Error "Disco bin path not found: $DiscoBinPath"
|
Write-Error "Disco bin path not found: $DiscoBinPath"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -31,7 +28,7 @@ $requiredDlls = @("Disco.Services.dll", "Disco.Models.dll", "Disco.Data.dll")
|
|||||||
foreach ($dll in $requiredDlls) {
|
foreach ($dll in $requiredDlls) {
|
||||||
$dllPath = Join-Path $DiscoBinPath $dll
|
$dllPath = Join-Path $DiscoBinPath $dll
|
||||||
if (-not (Test-Path $dllPath)) {
|
if (-not (Test-Path $dllPath)) {
|
||||||
Write-Error "Required assembly not found: $dllPath`nMake sure '$DiscoBinPath' contains the Disco assemblies."
|
Write-Error "Required assembly not found: $dllPath"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,52 +36,31 @@ Write-Host "All required Disco assemblies found" -ForegroundColor Green
|
|||||||
|
|
||||||
# --- Find MSBuild ---
|
# --- Find MSBuild ---
|
||||||
$msbuild = $null
|
$msbuild = $null
|
||||||
|
|
||||||
# Try VS2022/2019 via vswhere
|
|
||||||
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
||||||
if (Test-Path $vsWhere) {
|
if (Test-Path $vsWhere) {
|
||||||
$msbuild = & $vsWhere -latest -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\MSBuild.exe" 2>$null | Select-Object -First 1
|
$msbuild = & $vsWhere -latest -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\MSBuild.exe" 2>$null | Select-Object -First 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Try .NET Framework MSBuild
|
|
||||||
if (-not $msbuild -or -not (Test-Path $msbuild)) {
|
if (-not $msbuild -or -not (Test-Path $msbuild)) {
|
||||||
$frameworkMSBuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
|
$msbuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
|
||||||
if (Test-Path $frameworkMSBuild) {
|
|
||||||
$msbuild = $frameworkMSBuild
|
|
||||||
}
|
}
|
||||||
}
|
if (-not (Test-Path $msbuild)) {
|
||||||
|
Write-Error "MSBuild not found."
|
||||||
if (-not $msbuild -or -not (Test-Path $msbuild)) {
|
|
||||||
Write-Error "MSBuild not found. Install Visual Studio Build Tools or .NET Framework 4.7.2 Developer Pack."
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
Write-Host "Using MSBuild: $msbuild" -ForegroundColor Gray
|
Write-Host "Using MSBuild: $msbuild" -ForegroundColor Gray
|
||||||
|
|
||||||
# --- Create temp csproj with resolved assembly paths ---
|
# --- 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 HintPaths to point at the single Disco bin directory
|
# Replace ALL HintPath entries to point at DiscoBinPath
|
||||||
$csprojContent = $csprojContent -replace '<HintPath>[^<]*Disco\.Models\.dll</HintPath>', "<HintPath>$DiscoBinPath\Disco.Models.dll</HintPath>"
|
# This catches Disco.Models, Disco.Data, Disco.Services, Newtonsoft.Json,
|
||||||
$csprojContent = $csprojContent -replace '<HintPath>[^<]*Disco\.Data\.dll</HintPath>', "<HintPath>$DiscoBinPath\Disco.Data.dll</HintPath>"
|
# System.Web.Mvc, System.Web.WebPages, System.Web.Razor, etc.
|
||||||
$csprojContent = $csprojContent -replace '<HintPath>[^<]*Disco\.Services\.dll</HintPath>', "<HintPath>$DiscoBinPath\Disco.Services.dll</HintPath>"
|
$csprojContent = [regex]::Replace($csprojContent, '<HintPath>[^<]+\\([^\\<]+\.dll)</HintPath>', "<HintPath>$DiscoBinPath\`$1</HintPath>")
|
||||||
|
|
||||||
# Newtonsoft.Json - use from Disco bin
|
|
||||||
$newtonsoftPath = Join-Path $DiscoBinPath "Newtonsoft.Json.dll"
|
|
||||||
if (Test-Path $newtonsoftPath) {
|
|
||||||
$csprojContent = $csprojContent -replace '<HintPath>[^<]*Newtonsoft\.Json\.dll</HintPath>', "<HintPath>$newtonsoftPath</HintPath>"
|
|
||||||
}
|
|
||||||
|
|
||||||
# System.Web.Mvc - use from Disco bin if available
|
|
||||||
$mvcPath = Join-Path $DiscoBinPath "System.Web.Mvc.dll"
|
|
||||||
if (Test-Path $mvcPath) {
|
|
||||||
# Replace the strong-name reference with a HintPath reference
|
|
||||||
$csprojContent = $csprojContent -replace '<Reference Include="System\.Web\.Mvc[^"]*"[^/]*/>', "<Reference Include=""System.Web.Mvc""><HintPath>$mvcPath</HintPath><Private>False</Private></Reference>"
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempCsproj = Join-Path $PluginDir "$PluginName.build.csproj"
|
$tempCsproj = Join-Path $PluginDir "$PluginName.build.csproj"
|
||||||
$csprojContent | Set-Content $tempCsproj -Encoding UTF8
|
$csprojContent | Set-Content $tempCsproj -Encoding UTF8
|
||||||
Write-Host "Assembly references resolved" -ForegroundColor Green
|
Write-Host "Assembly references resolved to $DiscoBinPath" -ForegroundColor Green
|
||||||
|
|
||||||
# --- Build ---
|
# --- Build ---
|
||||||
Write-Host "`nBuilding $PluginName ($Configuration)..." -ForegroundColor Yellow
|
Write-Host "`nBuilding $PluginName ($Configuration)..." -ForegroundColor Yellow
|
||||||
@@ -109,31 +85,24 @@ Write-Host "Build successful: $pluginDll" -ForegroundColor Green
|
|||||||
# --- Generate Manifest ---
|
# --- Generate Manifest ---
|
||||||
Write-Host "`nGenerating manifest..." -ForegroundColor Yellow
|
Write-Host "`nGenerating manifest..." -ForegroundColor Yellow
|
||||||
|
|
||||||
# Copy Disco assemblies to build output for ManifestGenerator resolution
|
# Copy all DLLs from Disco bin to build output for ManifestGenerator
|
||||||
foreach ($dll in $requiredDlls) {
|
foreach ($dll in $requiredDlls) {
|
||||||
$src = Join-Path $DiscoBinPath $dll
|
Copy-Item (Join-Path $DiscoBinPath $dll) $buildOutput -Force -ErrorAction SilentlyContinue
|
||||||
Copy-Item $src $buildOutput -Force -ErrorAction SilentlyContinue
|
|
||||||
}
|
}
|
||||||
|
$extraDlls = @("EntityFramework.dll", "System.Web.Mvc.dll", "System.Web.WebPages.dll", "System.Web.Razor.dll", "RazorGenerator.Mvc.dll", "Newtonsoft.Json.dll")
|
||||||
# Copy other dependencies from Disco bin
|
foreach ($dep in $extraDlls) {
|
||||||
$depDlls = @("EntityFramework.dll", "System.Web.Mvc.dll", "RazorGenerator.Mvc.dll", "Newtonsoft.Json.dll")
|
|
||||||
foreach ($dep in $depDlls) {
|
|
||||||
$depPath = Join-Path $DiscoBinPath $dep
|
$depPath = Join-Path $DiscoBinPath $dep
|
||||||
if (Test-Path $depPath) {
|
if (Test-Path $depPath) { Copy-Item $depPath $buildOutput -Force -ErrorAction SilentlyContinue }
|
||||||
Copy-Item $depPath $buildOutput -Force -ErrorAction SilentlyContinue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Try Disco's ManifestGenerator if it exists in the bin path or nearby
|
# 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)) {
|
||||||
# Check parent directory
|
|
||||||
$manifestGenExe = Join-Path (Split-Path $DiscoBinPath -Parent) "Disco.Services.Plugins.ManifestGenerator.exe"
|
$manifestGenExe = Join-Path (Split-Path $DiscoBinPath -Parent) "Disco.Services.Plugins.ManifestGenerator.exe"
|
||||||
}
|
}
|
||||||
if (Test-Path $manifestGenExe) {
|
if (Test-Path $manifestGenExe) {
|
||||||
$useManifestGen = $true
|
$useManifestGen = $true
|
||||||
Write-Host "Found ManifestGenerator: $manifestGenExe" -ForegroundColor Gray
|
|
||||||
& $manifestGenExe $pluginDll
|
& $manifestGenExe $pluginDll
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Warning "ManifestGenerator failed, creating manifest manually..."
|
Write-Warning "ManifestGenerator failed, creating manifest manually..."
|
||||||
@@ -142,7 +111,6 @@ if (Test-Path $manifestGenExe) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (-not $useManifestGen) {
|
if (-not $useManifestGen) {
|
||||||
# Create manifest.json manually
|
|
||||||
$version = [System.Reflection.AssemblyName]::GetAssemblyName($pluginDll).Version
|
$version = [System.Reflection.AssemblyName]::GetAssemblyName($pluginDll).Version
|
||||||
$manifest = [ordered]@{
|
$manifest = [ordered]@{
|
||||||
Id = $PluginName
|
Id = $PluginName
|
||||||
@@ -160,13 +128,13 @@ if (-not $useManifestGen) {
|
|||||||
Write-Host "Manual manifest.json created" -ForegroundColor Green
|
Write-Host "Manual manifest.json created" -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Package as .discoPlugin ---
|
# --- Package ---
|
||||||
Write-Host "`nPackaging .discoPlugin file..." -ForegroundColor Yellow
|
Write-Host "`nPackaging .discoPlugin file..." -ForegroundColor Yellow
|
||||||
|
|
||||||
# Disco-provided assemblies to exclude from the package
|
|
||||||
$excludePatterns = @(
|
$excludePatterns = @(
|
||||||
"Disco.Models.*", "Disco.Data.*", "Disco.Services.*", "Disco.Web.*", "Disco.BI.*",
|
"Disco.Models.*", "Disco.Data.*", "Disco.Services.*", "Disco.Web.*", "Disco.BI.*",
|
||||||
"EntityFramework.*", "System.Web.Mvc.*", "RazorGenerator.Mvc.*", "Newtonsoft.Json.*",
|
"EntityFramework.*", "System.Web.Mvc.*", "System.Web.WebPages.*", "System.Web.Razor.*",
|
||||||
|
"RazorGenerator.Mvc.*", "Newtonsoft.Json.*",
|
||||||
"*.build.csproj", "*.discoPlugin"
|
"*.build.csproj", "*.discoPlugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -177,16 +145,13 @@ if (-not $version) {
|
|||||||
$packageName = "$PluginName-$($version.ToString()).discoPlugin"
|
$packageName = "$PluginName-$($version.ToString()).discoPlugin"
|
||||||
$packagePath = Join-Path $PluginDir $packageName
|
$packagePath = Join-Path $PluginDir $packageName
|
||||||
|
|
||||||
# Remove old packages
|
|
||||||
Get-ChildItem $PluginDir -Filter "*.discoPlugin" | Remove-Item -Force
|
Get-ChildItem $PluginDir -Filter "*.discoPlugin" | Remove-Item -Force
|
||||||
|
|
||||||
# Collect files for packaging (exclude Disco-provided assemblies)
|
|
||||||
$filesToPackage = Get-ChildItem $buildOutput -Recurse -File | Where-Object {
|
$filesToPackage = Get-ChildItem $buildOutput -Recurse -File | Where-Object {
|
||||||
$file = $_.Name
|
$file = $_.Name
|
||||||
-not ($excludePatterns | Where-Object { $file -like $_ })
|
-not ($excludePatterns | Where-Object { $file -like $_ })
|
||||||
}
|
}
|
||||||
|
|
||||||
# Build package in temp directory
|
|
||||||
$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 $filesToPackage) {
|
||||||
|
|||||||
Reference in New Issue
Block a user