-
-
Save dradovic/38914ec4bba343ecbb2c88548ca32f56 to your computer and use it in GitHub Desktop.
PowerShell Script to Find (and delete) all excluded files in a Visual Studio Solution
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
<# | |
.SYNOPSIS | |
Find all files excluded from a Visual Studio solution with options to delete. | |
.DESCRIPTION | |
Finds all excluded files in all projects in the provided Visual Studio solution with options to delete the files. | |
.PARAMETER Solution | |
The path to the .sln file | |
.PARAMETER VsVersion | |
The Visual Studio version (10, 11, 12) (Used to locate the tf.exe file) | |
.PARAMETER SvnDelete | |
Mark files as deleted in SVN | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Position=0, Mandatory=$true)] | |
[string]$Solution, | |
[Parameter(Mandatory=$false)] | |
[ValidateRange(10,12)] | |
[int] $VsVersion = 12, | |
[switch]$SvnDelete | |
) | |
$ErrorActionPreference = "Stop" | |
$solutionDir = Split-Path $Solution | % { (Resolve-Path $_).Path } | |
$projects = Select-String -Path $Solution -Pattern 'Project.*"(?<file>.*\.csproj)".*' ` | |
| % { $_.Matches[0].Groups[1].Value } ` | |
| % { Join-Path $solutionDir $_ } | |
$excluded = $projects | % { | |
$projectDir = Split-Path $_ | |
Write-Host "Analyzing" $_ | |
$projectFiles = Select-String -Path $_ -Pattern '<(Compile|None|Content|EmbeddedResource) Include="(.*)".*' ` | |
| % { $_.Matches[0].Groups[2].Value } ` | |
| % { Join-Path $projectDir $_ } | |
$diskFiles = Get-ChildItem -Path $projectDir -Recurse ` | |
| ? { !$_.PSIsContainer } ` | |
| % { $_.FullName } ` | |
| ? { $_ -match ".cs$" } ` | |
| ? { $_ -notmatch "\\obj\\" } | |
(compare-object $diskFiles $projectFiles -PassThru) | Where { $_.SideIndicator -eq '<=' } | |
} | |
Write-Host "Found" $excluded.count "excluded files" | |
if ($SvnDelete) | |
{ | |
Write-Host "SVN deleting excluded files..." | |
$excluded | % { | |
[Array]$arguments = @("delete", "`"$_`"") | |
& svn $arguments | |
} | |
} | |
else | |
{ | |
Write-Host "SvnDelete was not specified. Listing excluded files only..." | |
$excluded | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment