Ta rozszerzona wersja skryptu PS autorstwa Danny'ego Tuppeny'ego pokazuje odniesienia do plików csproj i vcxproj , a także obsługuje
-Depth - maksymalna długość łańcucha zależności
-Like - wyświetla tylko łańcuchy zależności zaczynające się od projektów o nazwie -jak $ Like
-UntilLike - ucina łańcuchy zależności w projektach o nazwie $ UntilLike
-Reverse - wyświetla odwrócone łańcuchy zależności ( [proj] <- [referencing proj] )
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]$RootFolder = ".",
[Parameter(Mandatory=$false)]
[string]$Like = "*",
[Parameter(Mandatory=$false)]
[string]$UntilLike = "*",
[Parameter(Mandatory=$false)]
[switch]$Reverse,
[Parameter(Mandatory=$false)]
[int]$Depth=1
)
$arrow = if ($script:Reverse) { "<-" } else { "->" }
Function PrintTree ($projectNameToProjectNameList, $projectName, $maxDepth = 1, $prefix = "")
{
$print = $script:UntilLike -eq "*" -or $projectName -Like $script:UntilLike
$stop = $projectNameToProjectNameList[$projectName].count -eq 0 -or $maxDepth -eq 0 -or ($script:UntilLike -ne "*" -and $projectName -Like $script:UntilLike)
if ($stop) {
if ($print) {
$prefix + "[$projectName]"
}
} else {
$prefix += "[$projectName] $arrow "
--$maxDepth
$projectNameToProjectNameList[$projectName] | % { PrintTree $projectNameToProjectNameList $_ $maxDepth $prefix }
}
}
Function Get-ProjectReferences ($rootFolder)
{
$projectFiles = Get-ChildItem $rootFolder -Filter *.csproj -Recurse
$projectFiles += Get-ChildItem $rootFolder -Filter *.vcxproj -Recurse
$ns = @{ defaultNamespace = "http://schemas.microsoft.com/developer/msbuild/2003" }
$projectGuidToProjectName = @{}
$projectNameToProjectReferenceGuidList = @{}
$projectFiles | ForEach-Object {
$projectFile = $_ | Select-Object -ExpandProperty FullName
$projectName = $_ | Select-Object -ExpandProperty BaseName
$projectXml = [xml](Get-Content $projectFile)
$projectGuid = $projectXml | Select-Xml '//defaultNamespace:ProjectGuid' -Namespace $ns | Select-Object -ExpandProperty Node | Select-Object -ExpandProperty "#text" | % { $_ -as [Guid] }
$projectGuidToProjectName[$projectGuid] = $projectName
$projectReferenceGuids = $projectXml | Select-Xml '//defaultNamespace:ProjectReference/defaultNamespace:Project' -Namespace $ns | Select-Object -ExpandProperty Node | Select-Object -ExpandProperty "#text" | % { $_ -as [Guid] }
if ($null -eq $projectReferenceGuids) { $projectReferenceGuids = @() }
$projectNameToProjectReferenceGuidList[$projectName] = $projectReferenceGuids
}
$projectNameToProjectReferenceNameList = @{}
foreach ($projectName in $projectNameToProjectReferenceGuidList.keys) {
$projectNameToProjectReferenceNameList[$projectName] = $projectNameToProjectReferenceGuidList[$projectName] | % { $projectGuidToProjectName[$_] } | sort
}
if ($script:Reverse) {
$projectReferenceNameToProjectNameList = @{}
foreach ($projectName in $projectNameToProjectReferenceNameList.keys) {
foreach ($projectReferenceName in $projectNameToProjectReferenceNameList[$projectName]) {
if (!$projectReferenceNameToProjectNameList.ContainsKey($projectReferenceName)) { $projectReferenceNameToProjectNameList[$projectReferenceName] = @() }
$projectReferenceNameToProjectNameList[$projectReferenceName] += $projectName
}
}
foreach ($projectName in $projectReferenceNameToProjectNameList.keys -Like $script:Like) {
PrintTree $projectReferenceNameToProjectNameList $projectName $script:Depth
}
} else {
foreach ($projectName in $projectNameToProjectReferenceNameList.keys -Like $script:Like) {
PrintTree $projectNameToProjectReferenceNameList $projectName $script:Depth
}
}
}
Get-ProjectReferences $RootFolder