Skip to content

Instantly share code, notes, and snippets.

@vardars
Last active October 9, 2015 13:32
Show Gist options
  • Save vardars/3e2fa430bcb9ddab2336 to your computer and use it in GitHub Desktop.
Save vardars/3e2fa430bcb9ddab2336 to your computer and use it in GitHub Desktop.
Create project dependencies from solution
# http://blog.dantup.com/2012/05/free-dependency-graph-generation-using-powershell-and-yuml/
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 + "] -> [" + $_ + "]" }
}
}
@vardars
Copy link
Author

vardars commented Oct 9, 2015

Usage:
$excludedProjects = "Test1", "Test2"
Get-ProjectReferences "C:\Users\DanTup\Documents\MyProject" -excludeProjectsContaining $excludedProjects | Out-File "C:\Users\DanTup\Documents\MyProject\References.txt"

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