Skip to content

Commit 59cd32b

Browse files
committed
Add -NoCache switch and improve error handling in Build.ps1
- Add -NoCache parameter to force rebuild bypassing cache - Re-find output DLL after build to handle first-time builds - Improve error messages to show expected DLL path - Update header to clarify this is an auto-generated file
1 parent 5c2cd49 commit 59cd32b

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

Build.ps1

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# The original of this file is in the PostSharp.Engineering repo.
2-
# You can generate this file using `./Build.ps1 generate-scripts`.
1+
# *** DO NOT EDIT THIS FILE DIRECTLY ***
2+
# This file is auto-generated from src/PostSharp.Engineering.BuildTools/Resources/Build.ps1
3+
# Edit the source version, then run `./Build.ps1 generate-scripts` to regenerate this file.
34

45
[CmdletBinding(PositionalBinding = $false)]
56
param(
67
[switch]$Interactive, # Opens an interactive PowerShell session
78
[switch]$StartVsmon, # Enable the remote debugger.
9+
[switch]$NoCache, # Bypass the build cache for `eng`, and force a rebuild.
810
[Parameter(ValueFromRemainingArguments)]
911
[string[]]$BuildArgs # Arguments passed to `Build.ps1` within the container.
1012
)
@@ -57,7 +59,12 @@ if (-not $Interactive -or $BuildArgs)
5759

5860
$needsBuild = $false
5961

60-
if (-not $outputDll -or -not (Test-Path $outputDll))
62+
if ($NoCache)
63+
{
64+
# Cache bypassed by -NoCache switch
65+
$needsBuild = $true
66+
}
67+
elseif (-not $outputDll -or -not (Test-Path $outputDll))
6168
{
6269
# DLL doesn't exist, need to build
6370
$needsBuild = $true
@@ -91,18 +98,28 @@ if (-not $Interactive -or $BuildArgs)
9198
if ($needsBuild)
9299
{
93100
# Build is needed
94-
Write-Host "Build cache invalid, rebuilding..." -ForegroundColor Cyan
101+
Write-Host "Rebuilding Build$ProductName..." -ForegroundColor Cyan
95102
& dotnet build $projectPath
96103
if ($LASTEXITCODE -ne 0)
97104
{
98105
throw "Build failed with exit code $LASTEXITCODE"
99106
}
100107

108+
# Re-find the output DLL after build
109+
if (Test-Path $binDebugPath)
110+
{
111+
$outputDll = Get-ChildItem -Path $binDebugPath -Filter "Build$ProductName.dll" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 | ForEach-Object { $_.FullName }
112+
}
113+
101114
# Update the DLL timestamp to mark the cache as valid
102115
if ($outputDll -and (Test-Path $outputDll))
103116
{
104117
(Get-Item $outputDll).LastWriteTime = Get-Date
105118
}
119+
else
120+
{
121+
throw "Build succeeded but output DLL '$outputDll' not found."
122+
}
106123
}
107124
else
108125
{
@@ -112,7 +129,7 @@ if (-not $Interactive -or $BuildArgs)
112129
# Run the project using dotnet exec (faster than dotnet run)
113130
if (-not $outputDll -or -not (Test-Path $outputDll))
114131
{
115-
throw "Output DLL not found at: $outputDll"
132+
throw "Output DLL not found. Expected path: '$outputDll'."
116133
}
117134

118135
& dotnet exec $outputDll $BuildArgs

src/PostSharp.Engineering.BuildTools/Resources/Build.ps1

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# The original of this file is in the PostSharp.Engineering repo.
2-
# You can generate this file using `./Build.ps1 generate-scripts`.
1+
# *** DO NOT EDIT THIS FILE DIRECTLY ***
2+
# This file is auto-generated from src/PostSharp.Engineering.BuildTools/Resources/Build.ps1
3+
# Edit the source version, then run `./Build.ps1 generate-scripts` to regenerate this file.
34

45
[CmdletBinding(PositionalBinding = $false)]
56
param(
67
[switch]$Interactive, # Opens an interactive PowerShell session
78
[switch]$StartVsmon, # Enable the remote debugger.
9+
[switch]$NoCache, # Bypass the build cache for `eng`, and force a rebuild.
810
[Parameter(ValueFromRemainingArguments)]
911
[string[]]$BuildArgs # Arguments passed to `Build.ps1` within the container.
1012
)
@@ -57,7 +59,12 @@ if (-not $Interactive -or $BuildArgs)
5759

5860
$needsBuild = $false
5961

60-
if (-not $outputDll -or -not (Test-Path $outputDll))
62+
if ($NoCache)
63+
{
64+
# Cache bypassed by -NoCache switch
65+
$needsBuild = $true
66+
}
67+
elseif (-not $outputDll -or -not (Test-Path $outputDll))
6168
{
6269
# DLL doesn't exist, need to build
6370
$needsBuild = $true
@@ -91,28 +98,34 @@ if (-not $Interactive -or $BuildArgs)
9198
if ($needsBuild)
9299
{
93100
# Build is needed
94-
Write-Host "Build cache invalid, rebuilding..." -ForegroundColor Cyan
101+
Write-Host "Building Build$ProductName..." -ForegroundColor Cyan
95102
& dotnet build $projectPath
96103
if ($LASTEXITCODE -ne 0)
97104
{
98105
throw "Build failed with exit code $LASTEXITCODE"
99106
}
100107

108+
# Re-find the output DLL after build
109+
if (Test-Path $binDebugPath)
110+
{
111+
$outputDll = Get-ChildItem -Path $binDebugPath -Filter "Build$ProductName.dll" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 | ForEach-Object { $_.FullName }
112+
}
113+
101114
# Update the DLL timestamp to mark the cache as valid
102115
if ($outputDll -and (Test-Path $outputDll))
103116
{
104117
(Get-Item $outputDll).LastWriteTime = Get-Date
105118
}
119+
else
120+
{
121+
throw "Build succeeded but output DLL '$outputDll' not found."
122+
}
106123
}
107-
else
108-
{
109-
Write-Host "Build cache valid, skipping build." -ForegroundColor Green
110-
}
111-
124+
112125
# Run the project using dotnet exec (faster than dotnet run)
113126
if (-not $outputDll -or -not (Test-Path $outputDll))
114127
{
115-
throw "Output DLL not found at: $outputDll"
128+
throw "Output DLL not found. Expected path: '$outputDll'."
116129
}
117130

118131
& dotnet exec $outputDll $BuildArgs

0 commit comments

Comments
 (0)