Skip to content

Instantly share code, notes, and snippets.

@tkapin
Created March 16, 2023 19:50
Show Gist options
  • Save tkapin/e6978cec9e5fde45281618f1fb57068e to your computer and use it in GitHub Desktop.
Save tkapin/e6978cec9e5fde45281618f1fb57068e to your computer and use it in GitHub Desktop.
Arcade services project references
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
param(
[string]$Path = $(Get-Location)
)
Set-StrictMode -Version 3.0
# Crude script for mapping project references in VS solution
Function Mermaidify([string] $str) {
return "$($str.Replace(".","_"))"
}
Function Get-ProjectReferences($rootFolder)
{
Write-Output "flowchart LR"
$projectFiles = Get-ChildItem $rootFolder -Filter *.csproj -Recurse
# clusters representing paths
$subgraphs = @{}
foreach($projectFile in $projectFiles) {
$parentDirName = $projectFile.Directory.Parent.Name
if ($subgraphs[$parentDirName]) {
$subgraphs[$parentDirName] += $projectFile.BaseName
} else {
$subgraphs[$parentDirName] = @($projectFile.BaseName)
}
}
foreach($subgraph in $subgraphs.GetEnumerator()) {
Write-Output "subgraph $(Mermaidify($subgraph.Name))_cluster[$($subgraph.Name)]"
foreach ($node in $subgraph.Value) {
Write-Output " $(Mermaidify($node))[$node]"
}
Write-Output "end"
}
# dependencies
foreach($projectFile in $projectFiles) {
$projectName = $projectFile.BaseName
$projectReferenceNodes = Select-Xml -Path $projectFile.FullName -XPath "/Project/ItemGroup/ProjectReference/@Include"
foreach($projectReferenceNode in $projectReferenceNodes) {
$projectReference = [System.IO.Path]::GetFileNameWithoutExtension($projectReferenceNode.Node.Value)
Write-Output "$(Mermaidify($projectName))-->$(Mermaidify($projectReference))"
}
}
}
Get-ProjectReferences $Path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment