-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGet-ProjectsWithProperty.ps1
54 lines (47 loc) · 1.95 KB
/
Get-ProjectsWithProperty.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
44
45
46
47
48
49
50
51
52
53
54
<#
.SYNOPSIS
This returns a set of objects composed of (ProjectName, ProjectPath, PropertyName, PropertyValue)
#>
function Get-ProjectsWithProperty
{
[CmdletBinding()]
[OutputType([System.Object[]])]
Param(
[string] $SolutionFilePath,
[string] $PropertyName
)
[PSObject[]]$returnValue = @()
$projectFilePaths = Get-ProjectFiles -SolutionFilePath $SolutionFilePath
foreach ($projectFilePath in $projectFilePaths)
{
$projFileContent = [xml] (Get-Content -Path $projectFilePath)
if (-Not ($projFileContent | Get-Member -Name Project))
{
Write-Warning "Project file '$projectFilePath' does not have a <project> element"
continue
}
if (-Not ($projFileContent.Project | Get-Member -Name PropertyGroup))
{
Write-Warning "Project file '$projectFilePath' does not have any <propertygroup> elements"
continue
}
if (-Not ($projFileContent.Project.PropertyGroup | Where-Object {$_ | Get-Member -Name $PropertyName} ))
{
Write-Verbose "Project file '$projectFilePath' does not have any elements matching property name $PropertyName"
continue
}
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($projectFilePath)
$matches = @($projFileContent.Project.PropertyGroup | Where-Object {$_ | Get-Member -Name $PropertyName} | Select-Object -Property $PropertyName -Unique)
Write-Verbose "Project file has $($matches.Count) matching properties"
foreach ($match in $matches)
{
$props = @{'ProjectName'=$projectName;
'ProjectFilePath'=$projectFilePath;
'PropertyName'=$PropertyName;
'PropertyValue'=$match.$PropertyName}
$obj = New-Object -TypeName PSObject -Property $props
$returnValue += $obj
}
}
return $returnValue
}