D:删除构建文件,增加调试脚本

This commit is contained in:
jimmy committed 2025-12-29 10:08:26 +08:00
1 parent 3b89b2d722
commit d133bacf55
40 files changed
+1180 -1066

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
# ========================================
# PowerShell 深度清理脚本
# 删除所有构建产物、缓存、临时文件
# ========================================
Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "Sharp-Basic 深度清理工具" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""
# 切换到项目根目录
Set-Location (Join-Path $PSScriptRoot "..")
# 统计删除的目录和文件数量
$deletedDirs = 0
$deletedFiles = 0
# 1. 删除所有 bin 目录
Write-Host "[1/7] 正在删除所有 bin 目录..." -ForegroundColor Yellow
Get-ChildItem -Path . -Recurse -Directory -Filter "bin" -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host " 删除: $($_.FullName)" -ForegroundColor Gray
Remove-Item $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
$deletedDirs++
}
# 2. 删除所有 obj 目录
Write-Host ""
Write-Host "[2/7] 正在删除所有 obj 目录..." -ForegroundColor Yellow
Get-ChildItem -Path . -Recurse -Directory -Filter "obj" -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host " 删除: $($_.FullName)" -ForegroundColor Gray
Remove-Item $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
$deletedDirs++
}
# 3. 删除 .vs 目录(Visual Studio 缓存)
Write-Host ""
Write-Host "[3/7] 正在删除 .vs 目录..." -ForegroundColor Yellow
Get-ChildItem -Path . -Recurse -Directory -Filter ".vs" -Force -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host " 删除: $($_.FullName)" -ForegroundColor Gray
Remove-Item $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
$deletedDirs++
}
# 4. 删除 TestResults 目录
Write-Host ""
Write-Host "[4/7] 正在删除 TestResults 目录..." -ForegroundColor Yellow
Get-ChildItem -Path . -Recurse -Directory -Filter "TestResults" -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host " 删除: $($_.FullName)" -ForegroundColor Gray
Remove-Item $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
$deletedDirs++
}
# 5. 删除临时文件
Write-Host ""
Write-Host "[5/7] 正在删除临时文件..." -ForegroundColor Yellow
$tempPatterns = @("*.tmp", "*.temp", "*.log", "*.cache", "*.bak", "*.user")
foreach ($pattern in $tempPatterns) {
Get-ChildItem -Path . -Recurse -File -Filter $pattern -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host " 删除: $($_.FullName)" -ForegroundColor Gray
Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue
$deletedFiles++
}
}
# 6. 使用 dotnet clean
Write-Host ""
Write-Host "[6/7] 使用 dotnet clean 清理解决方案..." -ForegroundColor Yellow
Push-Location "src\Sharp"
dotnet clean Sharp.sln --verbosity minimal
Pop-Location
# 7. 清理 NuGet 包缓存(可选,慎用)
Write-Host ""
Write-Host "[7/7] 是否清理 NuGet 包缓存?" -ForegroundColor Yellow
Write-Host " 警告: 这将删除所有缓存的 NuGet 包,下次构建需要重新下载" -ForegroundColor Red
$response = Read-Host " 输入 'yes' 继续,任意键跳过"
if ($response -eq 'yes') {
Write-Host " 正在清理 NuGet 缓存..." -ForegroundColor Gray
dotnet nuget locals all --clear
} else {
Write-Host " 已跳过 NuGet 缓存清理" -ForegroundColor Gray
}
# 显示统计信息
Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "清理完成!" -ForegroundColor Green
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host "删除的目录数: $deletedDirs" -ForegroundColor White
Write-Host "删除的文件数: $deletedFiles" -ForegroundColor White
Write-Host ""
# 暂停以便查看结果
Read-Host "按回车键退出"