Skip to content

Instantly share code, notes, and snippets.

@andrijac
Last active March 31, 2016 22:23
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 andrijac/9b091d154be9edab3655ac3baf2bfbf2 to your computer and use it in GitHub Desktop.
Save andrijac/9b091d154be9edab3655ac3baf2bfbf2 to your computer and use it in GitHub Desktop.
VS project dependency
# Script by Danny Tuppeny
# 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 + "] -> [" + $_ + "]" }
}
}
$excludedProjects = "Test1", "Test2"
Get-ProjectReferences "C:\Users\DanTup\Documents\MyProject" -excludeProjectsContaining $excludedProjects | Out-File "C:\Users\DanTup\Documents\MyProject\References.txt"
# http://stackoverflow.com/a/10472358/84852
Function Get-ProjectReferences ($rootFolder)
{
$projectFiles = Get-ChildItem $rootFolder -Filter *.csproj -Recurse
$ns = @{ defaultNamespace = "http://schemas.microsoft.com/developer/msbuild/2003" }
$projectFiles | ForEach-Object {
$projectFile = $_ | Select-Object -ExpandProperty FullName
$projectName = $_ | Select-Object -ExpandProperty BaseName
$projectXml = [xml](Get-Content $projectFile)
$projectReferences = $projectXml | Select-Xml '//defaultNamespace:ProjectReference/defaultNamespace:Name' -Namespace $ns | Select-Object -ExpandProperty Node | Select-Object -ExpandProperty "#text"
$projectReferences | ForEach-Object {
"[" + $projectName + "] -> [" + $_ + "]"
}
}
}
Get-ProjectReferences "target path" | Out-File "output path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment