Standardowo musiałem ręcznie usuwać zawartość tych katalogów, ale pomyślałem sobie czy nie lepiej jest napisać skrypt w PowerShell, który mógłby tą czynność wykonywać za mnie.
function Remove-CsprojBuildFiles
{
param(
[string]$dirPath = "."
)
$buildDirName = "bin","obj"
Write-Host "Deleting all `"$buildDirName`" dirs from $dirPath"
$dirsThatAreContainers = get-childitem $dirPath -Recurse |
? { $_.PSIsContainer}
$dirsThatAreBuildNames = $dirsThatAreContainers |
? {$buildDirName -contains $_.Name }
$dirsWhichContainsCsprojFile = $dirsThatAreBuildNames |
? { ((gci -path $_.Parent.FullName) |?{$_.FullName.Contains("csproj") } | Test-Any )}
$dirRemovedCounter= 0
foreach($dir in $dirsWhichContainsCsprojFile)
{
$dirFullPath = $dir.FullName
if(Test-path $dirFullPath )
{
Remove-Item -Path $dirFullPath -Recurse
$dirRemovedCounter+=1
}
else
{
Write-Error "Dir $dirFullPath not exists"
}
}
Write-Host "$dirRemovedCounter dirs removed from $dirPath"
}
Przydatna będzie funkcja test-any (taki Any z Linq), którą zapożyczyłem stąd.
function Test-Any() {
begin {
$any = $false
}
process {
$any = $true
}
end {
$any
}
}
Wywołanie polecenie do usuwania katalogów jest następująca:
Remove-CsprojBuildFiles "C:\code\'folder_to_solution'"

Brak komentarzy:
Prześlij komentarz