88 [Parameter (HelpMessage = " The path to the template used to generate the props file." )]
99 [string ]$templatePath = " $PSScriptRoot /MultiTargetAwareProjectReference.props.template" ,
1010
11- [Parameter (HelpMessage = " The path to the props file that contains the default MultiTarget values." )]
12- [string []]$multiTargetFallbackPropsPath = @ (" $PSScriptRoot /Defaults.props" ),
13-
1411 [Parameter (HelpMessage = " The placeholder text to replace when inserting the project file name into the template." )]
1512 [string ]$projectFileNamePlaceholder = " [ProjectFileName]" ,
1613
@@ -33,15 +30,50 @@ Set-Location $preWorkingDir;
3330# Insert csproj file name.
3431$csprojFileName = [System.IO.Path ]::GetFileName($relativeProjectPath );
3532$templateContents = $templateContents -replace [regex ]::escape($projectFileNamePlaceholder ), $csprojFileName ;
36- $projectName = (Get-Item (Split-Path - Parent $projectPath )).Name;
3733
3834# Insert project directory
3935$projectDirectoryRelativeToRoot = [System.IO.Path ]::GetDirectoryName($relativeProjectPath ).TrimStart(' .' ).TrimStart(' \' );
4036$templateContents = $templateContents -replace [regex ]::escape($projectRootPlaceholder ), " $projectDirectoryRelativeToRoot " ;
4137
4238# 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+
4577$templateContents = $templateContents -replace [regex ]::escape(" [IntendedTargets]" ), $multiTargets ;
4678$multiTargets = $multiTargets.Split (' ;' );
4779
0 commit comments