Skip to content

Commit 9be9d6b

Browse files
Add a -Clean option to build.ps1 (#878)
1 parent d7cee70 commit 9be9d6b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

build.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
.PARAMETER SkipRestore
6161
Skips restoring NuGet packages
6262
63+
.PARAMETER Clean
64+
If set, removes the repository-level Output/ and Obj/ directories before building.
65+
Useful to clear stale artifacts that can cause assembly version mismatches.
66+
6367
.PARAMETER SkipNative
6468
Skips building native C++ components. Use this for faster iterations when making purely managed code changes.
6569
@@ -134,6 +138,10 @@
134138
.\build.ps1 -RunTests
135139
Builds Debug x64 including test projects and runs all tests.
136140
141+
.EXAMPLE
142+
.\build.ps1 -Clean
143+
Removes Output/ and Obj/ first, then builds Debug x64.
144+
137145
.EXAMPLE
138146
.\build.ps1 -Serial -Verbosity detailed
139147
Builds Debug x64 serially with detailed logging.
@@ -163,6 +171,7 @@ param(
163171
[string]$LogFile,
164172
[int]$TailLines,
165173
[switch]$SkipRestore,
174+
[switch]$Clean,
166175
[switch]$SkipNative,
167176
[switch]$SkipNativeTests,
168177
[switch]$SkipManagedTests,
@@ -391,6 +400,26 @@ try {
391400
$fwTasksDropPath = Join-Path $PSScriptRoot "BuildTools/FwBuildTasks/$Configuration/FwBuildTasks.dll"
392401

393402
Invoke-WithFileLockRetry -Context "FieldWorks build" -IncludeOmniSharp -RepoRoot $PSScriptRoot -Action {
403+
if ($Clean) {
404+
if ($InstallerOnly) {
405+
throw "-Clean cannot be used with -InstallerOnly because installer-only builds require existing Output\\<Configuration> artifacts."
406+
}
407+
408+
Write-Host "Cleaning build artifacts (Output/, Obj/) ..." -ForegroundColor Cyan
409+
$pathsToClean = @(
410+
(Join-Path $PSScriptRoot "Output"),
411+
(Join-Path $PSScriptRoot "Obj")
412+
)
413+
414+
foreach ($path in $pathsToClean) {
415+
if (Test-Path $path) {
416+
Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue
417+
}
418+
}
419+
420+
Write-Host "Clean complete." -ForegroundColor Green
421+
}
422+
394423
# Initialize Visual Studio Developer environment
395424
Initialize-VsDevEnvironment
396425
Test-CvtresCompatibility

0 commit comments

Comments
 (0)