Created
September 15, 2022 14:17
-
-
Save ycaroafonso/bd5dc6be09237b746f014637bdebe397 to your computer and use it in GitHub Desktop.
delete unused package directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 20220915 Ycaro Afonso | |
$dirPackages = Join-Path -Path (Get-Location) -ChildPath 'packages' | |
[String[]]$dirXml = @() | |
foreach ($arqSln in (Get-ChildItem -Path .\* -Include *.sln)){ | |
$sln = Get-Content $arqSln | |
[String[]]$dirXml += [regex]::matches($sln, '"([^"]*).csproj"').value.replace('"','') | |
} | |
$diretoriosExistentes = Get-ChildItem -Path $dirPackages | Foreach-Object {$_.Name} | |
[String[]]$packagesUtilizados = @() | |
foreach ($arqXml in $dirXml) | |
{ | |
[xml]$xml = Get-Content $arqXml | |
[array]$service_arr = $xml.Project.ItemGroup.Reference | |
foreach ($service in $service_arr) | |
{ | |
if($service.HintPath){ | |
if ($packagesUtilizados -NotContains $service.HintPath.Split("\\")[2]) { | |
[String[]]$packagesUtilizados += $service.HintPath.Split("\\")[2] | |
} | |
} | |
} | |
} | |
$diretoriosExistentes | ForEach-Object { | |
if ($packagesUtilizados -NotContains $PSItem) { | |
"Item: [$PSItem]" | |
Remove-Item (Join-Path -Path $dirPackages -ChildPath $PSItem) -Recurse | |
} | |
} | |
#Remove-Item .\packagesUtilizados.txt | |
#Remove-Item .\diretoriosExistentes.txt | |
#$packagesUtilizados | Out-File -Append .\packagesUtilizados.txt | |
#$diretoriosExistentes | Out-File -Append .\diretoriosExistentes.txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment