Skip to content

Instantly share code, notes, and snippets.

@tcartwright
Last active July 23, 2024 18:51
Show Gist options
  • Save tcartwright/a3d5b57c46ae58024bf16f53d5e956fd to your computer and use it in GitHub Desktop.
Save tcartwright/a3d5b57c46ae58024bf16f53d5e956fd to your computer and use it in GitHub Desktop.
POWERSHELL: Compare a project file to the Directory.Packages.props file
Clear-Host
<#
PURPOSE: To scan all of the projects in a directory and compare the PackageReferences to the
Directory.Packages.props PackageVersions. Outputs if any are missing from the Directory.Packages.props
#>
$solutionFolder = "C:\..solution path..\"
$files = (Get-ChildItem $solutionFolder -Recurse -Filter "*.csproj").FullName
$xmlFilePath2 = "C:\..path..\Directory.Packages.props"
# Load the XML file
$xml2 = [xml](Get-Content $xmlFilePath2 -Raw)
$packageVersions = ($xml2.Project.ItemGroup.PackageVersion).Include
foreach ($file in $files) {
# Load the XML file
$xml = [xml](Get-Content $xmlFilePath -Raw)
# Get the PackageReference nodes
$packageReferences = ($xml.Project.ItemGroup.PackageReference).Include
$compares = Compare-Object -ReferenceObject $packageReferences -DifferenceObject $packageVersions
Write-Host -ForegroundColor Yellow $file
#$compares | Out-Host
# IF ANY SHOW IN THIS LIST THEY NEED TO BE ADDED TO THE PROPS FILE
$compares | Where-Object { $_.SideIndicator -eq "<=" } | Out-Host
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment