Skip to content

Instantly share code, notes, and snippets.

@decriptor
Created March 9, 2023 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decriptor/b91ce4e285e6fe7f4a4b9ef2946902f9 to your computer and use it in GitHub Desktop.
Save decriptor/b91ce4e285e6fe7f4a4b9ef2946902f9 to your computer and use it in GitHub Desktop.
Param(
[Parameter(Mandatory=$true)]
[string]$SolutionFilePath
)
# Get all lines that start with "Project("
$projectLines = Get-Content $SolutionFilePath | Where-Object { $_ -match '^Project\(' -and $_ -match '\.csproj"' }
# Extract project names and paths
$projects = $projectLines | ForEach-Object {
$matches1 = $_ -match '^Project\("([^"]+)"\) = "([^"]+)", "([^"]+)", "([^"]+)"$'
[PSCustomObject]@{
TypeGuid = $matches1[1]
Name = $matches1[2]
Path = $matches1[3]
Guid = $matches1[4]
}
}
# Loop through each project and extract package references
foreach ($project in $projects) {
Write-Host "Project: $($project.Name)"
$csprojPath = Join-Path (Split-Path $SolutionFilePath) $project.Path
$packageReferences = Get-Content $csprojPath | Where-Object { $_ -match '<PackageReference Include="([^"]+)" Version="([^"]+)"' } | ForEach-Object {
$matches1 = $_ -match '<PackageReference Include="([^"]+)" Version="([^"]+)"'
[PSCustomObject]@{
Name = $matches1[1]
Version = $matches1[2]
}
}
$packageReferences | Format-Table -AutoSize
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment