Az itt látható példa azokat a C# kódfájlokat listázza ki, amelyek árván maradtak, azaz ott vannak a fájlrendszerben, de nincsenek benne egy csproj fájlban.
Az egész számomra azért érdekes, mert szerintem igen tömören és elegánsan parsolják az xml csproj fájlt Powershellel.
A lopás árnyékát el nem kerülve, de idemásolom a példát a fenti forrástól:
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
Could you hire me? Contact me if you like what I’ve done in this article and think I can create value for your company with my skills.