:::: MENU ::::

Monday, July 21, 2008

I ran across a C# file that had been removed from its csproj file, but it hadn't been deleted from version control.  So James wrote a script (Chris Sidi had already written one, though) to find the .cs files that weren't in the "containing" .csproj file

 

param([string]$csproj = $(throw 'csproj file is required'))
 
$csproj = Resolve-Path $csproj
$dir = Split-Path $csproj
 
# get the files that are included in compilation
$xml = [xml](Get-Content $csproj)
$files_from_csproj = $xml.project.itemgroup | 
        %{ $_.Compile } | 
        %{ $_.Include } |
        ?{ $_ } | 
        %{ Join-Path $dir $_ } |
        Sort-Object
 
# get the files from the dir
$files_from_dir = Get-ChildItem $dir -Recurse -Filter *.cs |
        %{ $_.FullName } |
        Sort-Object
        
Compare-Object $files_from_csproj $files_from_dir

 

Categories: