Skip to content

Instantly share code, notes, and snippets.

@mahldcat
Created February 13, 2024 05:44
Show Gist options
  • Select an option

  • Save mahldcat/b1a7c6486ebb579007046e901a7bdff3 to your computer and use it in GitHub Desktop.

Select an option

Save mahldcat/b1a7c6486ebb579007046e901a7bdff3 to your computer and use it in GitHub Desktop.
Powershell script to generate a mermaid dep tree
param($slnFile = ".\ProjectWithDeps\ProjectWithDeps.sln")
function Get-ProjectFileWithoutExt{
param($path)
$fileName = Split-Path -Path $path -Leaf
return $fileName -replace '\.[^.]*$'
}
function Get-ProjectPackages{
param($path)
$packages = dotnet list $path package | Select-Object -skip 3
$a = @()
foreach($p in $packages){
if($p -eq ""){
continue
}
$pkg = $p -split '\s+' -ne ''
$a+= "$($pkg[1]) $($pkg[3])"
}
return $a
}
$slnPath = Resolve-Path $slnFile
$slnDir = Split-Path -Path $slnPath -Parent
$projects = dotnet sln $slnPath list | Select-Object -skip 2
Write-Output "flowchart TD"
foreach($project in $projects){
$projPath = resolve-path (join-Path $slnDir $project)
$projectName =Get-ProjectFileWithoutExt -path $projPath
$projDir = Split-Path -Path $projPath -Parent
$packages=Get-ProjectPackages -path $projPath
Write-Output "$projectName["
Write-Output " $projectName"
foreach($p in $packages){
Write-Output " $p"
}
Write-Output "]"
$deps = dotnet list $projPath reference | Select-object -skip 2
if($deps.Count -gt 0){
foreach($d in $deps){
$depPath = Resolve-Path (join-Path $projDir $d)
$depProj = Get-ProjectFileWithoutExt -path $depPath
Write-Output "$projectName --> $depProj"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment