merge: integrate local project metadata history

This commit is contained in:
Jimmy Gatsby committed 2026-10-27 20:36:32 +08:00
commit 3688dc708f
1 file changed
+85
+85
View File
@@ -0,0 +1,85 @@
# Clean redundant metadata from all project files
# Projects will inherit from Directory.Build.props
$ErrorActionPreference = "Stop"
Write-Host "Cleaning Project Metadata..." -ForegroundColor Cyan
# Get all .csproj files
$projectFiles = Get-ChildItem -Path "." -Filter "*.csproj" -Recurse |
Where-Object { $_.FullName -notmatch "\\obj\\" -and $_.FullName -notmatch "\\bin\\" }
Write-Host "Found $($projectFiles.Count) project files" -ForegroundColor Yellow
# Metadata properties to remove (will inherit from Directory.Build.props)
$metadataToRemove = @(
"Version",
"AssemblyVersion",
"FileVersion",
"Authors",
"Company",
"Product",
"Copyright",
"PackageId",
"PackageProjectUrl",
"RepositoryUrl",
"RepositoryType",
"PackageLicenseExpression"
)
$totalModified = 0
foreach ($projectFile in $projectFiles) {
Write-Host "`nProcessing: $($projectFile.Name)" -ForegroundColor Cyan
# Read file content
$lines = Get-Content -Path $projectFile.FullName -Encoding UTF8
$newLines = New-Object System.Collections.ArrayList
$modified = $false
$removedCount = 0
# Filter out metadata lines
foreach ($line in $lines) {
$shouldSkip = $false
# Check if line contains any metadata to remove
foreach ($metadata in $metadataToRemove) {
if ($line -match "<$metadata>.*</$metadata>") {
$shouldSkip = $true
$removedCount++
Write-Host " Removed: $metadata" -ForegroundColor Gray
break
}
}
# Skip comment lines
if ($line -match "<!--\s*(程序集元数据|NuGet 包元数据)\s*-->") {
$shouldSkip = $true
}
if (-not $shouldSkip) {
[void]$newLines.Add($line)
} else {
$modified = $true
}
}
# Save if modified
if ($modified) {
$newLines | Set-Content -Path $projectFile.FullName -Encoding UTF8
Write-Host " Updated ($removedCount properties removed)" -ForegroundColor Green
$totalModified++
} else {
Write-Host " No changes needed" -ForegroundColor DarkGray
}
}
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "Done! Updated $totalModified project files" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "`nProjects now inherit from Directory.Build.props:" -ForegroundColor Yellow
Write-Host " - Version, Authors, Copyright" -ForegroundColor White
Write-Host " - Repository URLs, License" -ForegroundColor White
Write-Host "`nProject-specific properties retained:" -ForegroundColor Yellow
Write-Host " - Description" -ForegroundColor White
Write-Host " - PackageTags" -ForegroundColor White