I'm aiming to accomplish the following with a PowerShell script. Most sub folders in "C:\Example-Path\src" contain a single .csproj file that includes a "Property Include" and "Version" attribute. I want to gather these attributes from every instance of a .csproj file across all sub folder and compile them into a spreadsheet, 1 column for each attribute. I've revised my work quite a bit to where I'm not getting errors anymore, however after the program runs the final excel sheets turns up empty and I can't seem to figure out why. My code is below, any input is greatly appreciated!
$Directory = dir C:\Example-Path\src -Directory
foreach ($d in $Directory) {
Write-Host "Working on directory $($d.FullName)..."
Get-ChildItem -Path "$($d.fullname)\*" -File -Recurse -filter '.csproj' |
ForEach-Object {
[xml]$file = get-content .\$_
$xmlProperties = $file.SelectNodes("/Project/ItemGroup/PackageReference")
$xmlProperties | Select-Object -Property Include, Version
} | Export-Excel -Path C:\Temp\ExamplExcel.xlsx -AutoSize -AutoFilter
}
Here is an example of the .csproj file I'm attempting to read from:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LazyCache.AspNetCore" Version="2.1.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Caching.Core\Caching.Core.csproj" />
<ProjectReference Include="..\Caching.SharedKernel\ Caching.SharedKernel.csproj" />
</ItemGroup>
</Project>