My code currently goes through a list of folders/subdirectories looking for '.csproj' files. The properties "Include" and "Version" are taken from the found .csproj file(s) and are exported to an excel sheet. While this works and I do get two columns for each property, I need to show the name of the file that each excel row entry belongs too. I haven't been able to find an approach to this. So in my final excel sheet, I need 3 rows: Include, Version, NameOfTheFile.
Through troubleshooting I added "$xml.name" after the line "Select-Object -Property Include, Version" and this added spaces in the excel sheet between each batch of properties. That's somewhat helpful, but the name of the files would be far more sufficient.
$Directory = Get-ChildItem C:\Repos\Common\Caching\src -Directory
$ErrorFiles = [System.Collections.Generic.List[string]]::new()
$result = foreach ($d in $Directory) {
Write-Host "Working on directory $($d.FullName)..."
$folders = Get-ChildItem -Path $d.FullName -File -Recurse -Filter *.csproj
foreach($folder in $folders) {
try {
$xml = [xml](Get-Content $folder.FullName -Raw)
$xml.SelectNodes("/Project/ItemGroup/PackageReference") |
Select-Object -Property Include, Version
$xml.Name
}
catch {
Write-Warning $_.Exception.Message
$ErrorFiles.Add($folder.FullName)
}
}
}
$result | Export-Excel -Path C:\Temp\ExampleExcel.xlsx -AutoSize -AutoFilter