Last active
September 8, 2024 21:22
-
-
Save fluxdigital/d79437f307b4f14c991a3bc12e83d747 to your computer and use it in GitHub Desktop.
PowerShell Script to Remove all TDS projects from an VS Solution
This file contains hidden or 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
#set variables for script | |
$solutionPath = "C:\Projects\myproject" #path to your VS Solution | |
$solutionName = "MyProject.sln" #the name of your VS Solution | |
$deleteTDSProjectsFromSolution = $true #if the script should remove the TDS projects from the solution file | |
$tidyUpTDSFilesAndFolders = $true #if the script should remove all physical TDS project files and .item/.yaml files on disk | |
$tidyUpParentFolders = $true #If the script should remove empty parent folders | |
#find all TDS projects | |
Push-Location $solutionPath | |
if($deleteTDSProjectsFromSolution){ | |
write-host "finding projects in solution: $($solutionName)..." | |
#delete them from vs project | |
dotnet sln $solutionName remove (ls -r **/*.scproj) | |
write-host "Deleting TDS Projects from VS solution File..." | |
} | |
if($tidyUpTDSFilesAndFolders){ | |
#find all TDS projects | |
$tdsProjects = Get-ChildItem -Path $srcPath -Recurse -Filter *.scproj | |
Write-Host "Tidying up $($tdsProjects.Count) TDS Project Folders..." | |
Write-Host "-------------------------------------------------------" | |
#loop and remove each folder from the Solution | |
foreach ($tdsProject in $tdsProjects) { | |
$parentfolderName = (get-item $tdsProject.FullName).Directory.FullName | |
$parentParent = (get-item $tdsProject.FullName).Directory.Parent.FullName | |
Write-Host " Processing Project: $($tdsProject.Name)" -ForegroundColor Magenta | |
Write-Host " --> Removing Folder: $($parentfolderName) ..." -ForegroundColor Yellow | |
Remove-Item -LiteralPath $parentfolderName -Force -Recurse | |
if($tidyUpParentFolders){ | |
$parentChildrenInfo = Get-ChildItem $parentParent | Measure-Object | |
Write-Host " --> Parent Folder Child Count: $($parentChildrenInfo.count) ..." -ForegroundColor Cyan | |
if($parentChildrenInfo.count -eq 0){ | |
Write-Host " removing parent folder..." | |
Remove-Item -LiteralPath $parentParent -Force -Recurse | |
} | |
else{ | |
Write-Host " skiping remove parent folder..." | |
} | |
} | |
} | |
} | |
write-host "done." -ForegroundColor Green | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment