|
1 | 1 | $ErrorActionPreference = 'Stop' |
2 | 2 |
|
3 | | -# Build the solution with DeployOnBuild — creates .zip packages under each |
4 | | -# web project's obj/Live/Package/ directory. |
5 | | -Write-Host '=== Building solution ===' |
6 | | -msbuild src\LocalGovIms.sln /p:Configuration=Live /p:DeployOnBuild=true /p:WebPublishMethod=Package /verbosity:minimal |
7 | | -if ($LASTEXITCODE -ne 0) { throw "MSBuild failed with exit code $LASTEXITCODE" } |
8 | | - |
9 | | -# Extract from the Web Deploy .zip packages IMMEDIATELY (same process, before |
10 | | -# any cleanup can occur). The zips nest content under a PackageTmp directory. |
11 | | -Write-Host '=== Extracting packages ===' |
| 3 | +# Step 1: Build the solution (compiles everything including libraries). |
| 4 | +Write-Host '=== Step 1: Building solution ===' |
| 5 | +msbuild src\LocalGovIms.sln /p:Configuration=Live /t:Build /verbosity:minimal |
| 6 | +if ($LASTEXITCODE -ne 0) { throw "Solution build failed" } |
| 7 | + |
| 8 | +# Step 2: Fix lib paths — solution maps Live->Release for libraries, but web |
| 9 | +# projects reference them at bin\Live\. Copy Release -> Live. |
| 10 | +Write-Host '=== Step 2: Fixing library paths ===' |
| 11 | +foreach ($lib in @('BusinessLogic', 'DataAccess', 'Web')) { |
| 12 | + $src = "C:\src\src\$lib\bin\Release" |
| 13 | + $dst = "C:\src\src\$lib\bin\Live" |
| 14 | + if (Test-Path $src) { |
| 15 | + New-Item -ItemType Directory -Force -Path $dst | Out-Null |
| 16 | + Copy-Item -Path "$src\*" -Destination $dst -Recurse -Force |
| 17 | + Write-Host " Copied $lib bin\Release -> bin\Live" |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +# Step 3: Publish each web project individually and extract immediately. |
| 22 | +# Using pipelinePreDeployCopyAllFilesToOneFolder which creates _PackageTempDir. |
| 23 | +# BuildProjectReferences=false prevents rebuilding libs (already built above). |
| 24 | +Write-Host '=== Step 3: Publishing web projects ===' |
12 | 25 | $projects = @( |
13 | | - @{ Name = 'PaymentPortal'; Dest = 'C:\build\portal' } |
14 | | - @{ Name = 'Admin'; Dest = 'C:\build\admin' } |
15 | | - @{ Name = 'Api'; Dest = 'C:\build\api' } |
| 26 | + @{ Csproj = 'src\PaymentPortal\PaymentPortal.csproj'; Dest = 'C:\build\portal' } |
| 27 | + @{ Csproj = 'src\Admin\Admin.csproj'; Dest = 'C:\build\admin' } |
| 28 | + @{ Csproj = 'src\Api\Api.csproj'; Dest = 'C:\build\api' } |
16 | 29 | ) |
17 | 30 |
|
18 | 31 | foreach ($proj in $projects) { |
19 | | - $zip = "C:\src\src\$($proj.Name)\obj\Live\Package\$($proj.Name).zip" |
20 | 32 | $dest = $proj.Dest |
21 | 33 | New-Item -ItemType Directory -Force -Path $dest | Out-Null |
22 | 34 |
|
23 | | - if (Test-Path $zip) { |
24 | | - $tmp = "C:\tmp_extract\$($proj.Name)" |
25 | | - Expand-Archive -Path $zip -DestinationPath $tmp -Force |
26 | | - |
27 | | - # Find PackageTmp inside the extracted zip |
28 | | - $ptDir = Get-ChildItem -Path $tmp -Recurse -Directory -Filter 'PackageTmp' | Select-Object -First 1 |
29 | | - if ($ptDir) { |
30 | | - Copy-Item -Path (Join-Path $ptDir.FullName '*') -Destination $dest -Recurse -Force |
31 | | - $fileCount = (Get-ChildItem $dest -Recurse -File).Count |
32 | | - $dllCount = (Get-ChildItem (Join-Path $dest 'bin') -File -ErrorAction SilentlyContinue).Count |
33 | | - Write-Host "$($proj.Name): $fileCount files, $dllCount DLLs" |
34 | | - } else { |
35 | | - Write-Host "WARNING: No PackageTmp found in $zip" |
36 | | - Copy-Item -Path (Join-Path $tmp '*') -Destination $dest -Recurse -Force |
| 35 | + Write-Host " Publishing $($proj.Csproj) -> $dest" |
| 36 | + msbuild $proj.Csproj ` |
| 37 | + /p:Configuration=Live ` |
| 38 | + /p:BuildProjectReferences=false ` |
| 39 | + /t:pipelinePreDeployCopyAllFilesToOneFolder ` |
| 40 | + "/p:_PackageTempDir=$dest" ` |
| 41 | + /verbosity:minimal |
| 42 | + |
| 43 | + if ($LASTEXITCODE -ne 0) { |
| 44 | + Write-Host " WARNING: pipelinePreDeployCopyAllFilesToOneFolder failed, trying WebPublishMethod=Package" |
| 45 | + msbuild $proj.Csproj ` |
| 46 | + /p:Configuration=Live ` |
| 47 | + /p:BuildProjectReferences=false ` |
| 48 | + /p:DeployOnBuild=true ` |
| 49 | + /p:WebPublishMethod=Package ` |
| 50 | + /verbosity:minimal |
| 51 | + |
| 52 | + # Extract from zip |
| 53 | + $name = [IO.Path]::GetFileNameWithoutExtension($proj.Csproj) |
| 54 | + $projDir = Split-Path $proj.Csproj -Parent |
| 55 | + $zip = "C:\src\$projDir\obj\Live\Package\$name.zip" |
| 56 | + if (Test-Path $zip) { |
| 57 | + $tmp = "C:\tmp_extract\$name" |
| 58 | + Expand-Archive -Path $zip -DestinationPath $tmp -Force |
| 59 | + $ptDir = Get-ChildItem -Path $tmp -Recurse -Directory -Filter 'PackageTmp' | Select-Object -First 1 |
| 60 | + if ($ptDir) { |
| 61 | + Copy-Item -Path "$($ptDir.FullName)\*" -Destination $dest -Recurse -Force |
| 62 | + } |
| 63 | + Remove-Item $tmp -Recurse -Force |
37 | 64 | } |
38 | | - Remove-Item $tmp -Recurse -Force |
39 | | - } else { |
40 | | - Write-Host "WARNING: $zip not found!" |
41 | | - Write-Host "Available zips:" |
42 | | - Get-ChildItem -Path 'C:\src\src' -Recurse -Filter '*.zip' -ErrorAction SilentlyContinue | ForEach-Object { Write-Host " $($_.FullName)" } |
43 | 65 | } |
| 66 | + |
| 67 | + $fileCount = (Get-ChildItem $dest -Recurse -File -ErrorAction SilentlyContinue).Count |
| 68 | + $dllCount = (Get-ChildItem "$dest\bin" -File -ErrorAction SilentlyContinue).Count |
| 69 | + Write-Host " Result: $fileCount files, $dllCount DLLs" |
44 | 70 | } |
45 | 71 |
|
46 | 72 | Write-Host '=== Build and extract complete ===' |
0 commit comments