-
Notifications
You must be signed in to change notification settings - Fork 7
/
Find-References.ps1
44 lines (37 loc) · 1.43 KB
/
Find-References.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<#
.SYNOPSIS
Finds a specific reference in any project in a solution. Uses the Match operator so partial reference names are ok.
#>
function Find-References
{
[CmdletBinding()]
Param(
[string] $SolutionFilePath
, [string] $ReferenceName
)
Write-Verbose "Using solution $SolutionFilePath"
$allProjects = Get-ProjectFiles -SolutionFilePath $SolutionFilePath
Write-Verbose "There are $($allProjects.Count) projects in this solution"
[PSObject[]]$matches = @()
foreach($projectFile in $allProjects)
{
Write-Verbose "Checking project file '$projectFile' for references"
$projFileContent = [xml](Get-Content $projectFile)
$references = @($projFileContent.Project.ItemGroup.Reference)
Write-Verbose "Project has $($references.Count) references"
foreach ($reference in $references)
{
if ($ReferenceName -eq "*" -or $reference.Include -match $ReferenceName)
{
Write-Verbose "Match found for reference $($reference.Include)"
$props = @{'ProjectFile'=$projectFile;
'ReferenceInclude'=$reference.Include;
'ReferencePath'=$reference.HintPath;}
$obj = (New-Object -TypeName PSObject -Property $props)
#$matches += $obj
Write-Output $obj
}
}
}
return $matches
}