Skip to content

Instantly share code, notes, and snippets.

@DanTup
Last active October 4, 2015 10:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DanTup/2623209 to your computer and use it in GitHub Desktop.
Save DanTup/2623209 to your computer and use it in GitHub Desktop.
Output Visual Studio project references for yuml.me
function Get-ProjectReferences
{
param(
[Parameter(Mandatory)]
[string]$rootFolder,
[string[]]$excludeProjectsContaining
)
dir $rootFolder -Filter *.csproj -Recurse |
# Exclude any files matching our rules
where { $excludeProjectsContaining -notlike "*$($_.BaseName)*" } |
Select-References
}
function Select-References
{
param(
[Parameter(ValueFromPipeline, Mandatory)]
[System.IO.FileInfo]$project,
[string[]]$excludeProjectsContaining
)
process
{
$projectName = $_.BaseName
[xml]$projectXml = Get-Content $_.FullName
$ns = @{ defaultNamespace = "http://schemas.microsoft.com/developer/msbuild/2003" }
$projectXml |
# Find the references xml nodes
Select-Xml '//defaultNamespace:ProjectReference/defaultNamespace:Name' -Namespace $ns |
# Get the node values
foreach { $_.node.InnerText } |
# Exclude any references pointing to projects that match our rules
where { $excludeProjectsContaining -notlike "*$_*" } |
# Output in yuml.me format
foreach { "[" + $projectName + "] -> [" + $_ + "]" }
}
}
$excludedProjects = "Test1", "Test2"
Get-ProjectReferences "C:\Users\DanTup\Documents\MyProject" -excludeProjectsContaining $excludedProjects | Out-File "C:\Users\DanTup\Documents\MyProject\References.txt"
@DanTup
Copy link
Author

DanTup commented May 6, 2012

Paste the output into yuml.me, and get something like this:
http://yuml.me/4f30e632

@pjvds
Copy link

pjvds commented May 6, 2012

Freaking awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment