-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathGet-MultiTargets.ps1
More file actions
53 lines (42 loc) · 1.88 KB
/
Get-MultiTargets.ps1
File metadata and controls
53 lines (42 loc) · 1.88 KB
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
<#
.SYNOPSIS
Retrieves the MultiTarget properties for a component.
.DESCRIPTION
This script retrieves the MultiTarget properties for a component by parsing the contents of the MultiTarget.props file.
It replaces placeholders in a template with the component-specific information, such as the csproj file name and component directory.
.PARAMETER component
The name of the component to retrieve MultiTarget properties from.
.OUTPUTS
An array of MultiTarget properties.
.EXAMPLE
Get-MultiTarget -component "MyComponent"
Retrieves the MultiTarget properties for the specified component.
#>
param (
[Parameter(Mandatory=$true)]
[string]$component
)
# Load multitarget preferences for component
# Folder layout is expected to match the Community Toolkit.
$componentPath = "$PSScriptRoot/../../components/$component";
$srcPath = Resolve-Path "$componentPath\src";
$samplePath = "$componentPath\samples";
# Uses the <MultiTarget> values from the source library component as the fallback for the sample component.
# This behavior also implemented in TargetFramework evaluation.
$multiTargetFallbackPropsPaths += @("$samplePath/MultiTarget.props", "$srcPath/MultiTarget.props", "$PSScriptRoot/Defaults.props")
# Load first available default
$fileContents = "";
foreach ($fallbackPath in $multiTargetFallbackPropsPaths) {
if (Test-Path $fallbackPath) {
$fileContents = Get-Content $fallbackPath -ErrorAction Stop;
break;
}
}
# Parse file contents
$regex = Select-String -Pattern '<MultiTarget>(.+?)<\/MultiTarget>' -InputObject $fileContents;
if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2) {
Write-Error "Couldn't get MultiTarget property from $path";
exit(-1);
}
$multiTargets = $regex.Matches.Groups[1].Value;
return $multiTargets.Split(';') | Where-Object { $_ -ne '' };