8
8
[Parameter (HelpMessage = " The path to the template used to generate the props file." )]
9
9
[string ]$templatePath = " $PSScriptRoot /MultiTargetAwareProjectReference.props.template" ,
10
10
11
- [Parameter (HelpMessage = " The path to the props file that contains the default MultiTarget values." )]
12
- [string []]$multiTargetFallbackPropsPath = @ (" $PSScriptRoot /Defaults.props" ),
13
-
14
11
[Parameter (HelpMessage = " The placeholder text to replace when inserting the project file name into the template." )]
15
12
[string ]$projectFileNamePlaceholder = " [ProjectFileName]" ,
16
13
@@ -33,15 +30,50 @@ Set-Location $preWorkingDir;
33
30
# Insert csproj file name.
34
31
$csprojFileName = [System.IO.Path ]::GetFileName($relativeProjectPath );
35
32
$templateContents = $templateContents -replace [regex ]::escape($projectFileNamePlaceholder ), $csprojFileName ;
36
- $projectName = (Get-Item (Split-Path - Parent $projectPath )).Name;
37
33
38
34
# Insert project directory
39
35
$projectDirectoryRelativeToRoot = [System.IO.Path ]::GetDirectoryName($relativeProjectPath ).TrimStart(' .' ).TrimStart(' \' );
40
36
$templateContents = $templateContents -replace [regex ]::escape($projectRootPlaceholder ), " $projectDirectoryRelativeToRoot " ;
41
37
42
38
# Load multitarget preferences for project
43
- $multiTargets = & $PSScriptRoot \GetMultiTargets.ps1 - ComponentName $projectName - ErrorAction Stop;
44
-
39
+ # Folder layout is expected to match the Community Toolkit.
40
+ $projectName = (Get-Item (Split-Path - Parent (Split-Path - Parent $projectPath ))).Name;
41
+ $componentPath = " $PSScriptRoot /../../components/$projectName " ;
42
+
43
+ $srcPath = Resolve-Path " $componentPath \src" ;
44
+ $samplePath = " $componentPath \samples" ;
45
+
46
+ # Uses the <MultiTarget> values from the source library project as the fallback for the sample project.
47
+ # This behavior also implemented in TargetFramework evaluation.
48
+ $multiTargetFallbackPropsPaths = @ ()
49
+
50
+ if ($projectPath.ToLower ().Contains(' sample' )) {
51
+ $multiTargetFallbackPropsPaths += @ (" $samplePath /MultiTarget.props" , " $srcPath /MultiTarget.props" )
52
+ } else {
53
+ $multiTargetFallbackPropsPaths += @ (" $srcPath /MultiTarget.props" )
54
+ }
55
+
56
+ $multiTargetFallbackPropsPaths += @ (" $PSScriptRoot /Defaults.props" )
57
+
58
+ # Load first available default
59
+ $fileContents = " " ;
60
+ foreach ($fallbackPath in $multiTargetFallbackPropsPaths ) {
61
+ if (Test-Path $fallbackPath ) {
62
+ $fileContents = Get-Content $fallbackPath - ErrorAction Stop;
63
+ break ;
64
+ }
65
+ }
66
+
67
+ # Parse file contents
68
+ $regex = Select-String - Pattern ' <MultiTarget>(.+?)<\/MultiTarget>' - InputObject $fileContents ;
69
+
70
+ if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2 ) {
71
+ Write-Error " Couldn't get MultiTarget property from $path " ;
72
+ exit (-1 );
73
+ }
74
+
75
+ $multiTargets = $regex.Matches.Groups [1 ].Value;
76
+
45
77
$templateContents = $templateContents -replace [regex ]::escape(" [IntendedTargets]" ), $multiTargets ;
46
78
$multiTargets = $multiTargets.Split (' ;' );
47
79
0 commit comments