55 [Parameter (HelpMessage = " A path to a .props file where generated content should be saved to." , Mandatory = $true )]
66 [string ]$outputPath ,
77
8- [Parameter (HelpMessage = " The path to the template used to generate the props file." )]
8+ [Parameter (HelpMessage = " The path to the template used to generate the props file." )]
99 [string ]$templatePath = " $PSScriptRoot /MultiTargetAwareProjectReference.props.template" ,
1010
1111 [Parameter (HelpMessage = " The path to the props file that contains the default MultiTarget values." )]
@@ -15,7 +15,11 @@ Param (
1515 [string ]$projectFileNamePlaceholder = " [ProjectFileName]" ,
1616
1717 [Parameter (HelpMessage = " The placeholder text to replace when inserting the project path into the template." )]
18- [string ]$projectRootPlaceholder = " [ProjectRoot]"
18+ [string ]$projectRootPlaceholder = " [ProjectRoot]" ,
19+
20+ [Parameter (HelpMessage = " Only projects that support these targets will have references generated for use by deployable heads." )]
21+ [ValidateSet (" uwp" , " wasdk" , " wpf" , " wasm" , " linuxgtk" , " macos" , " ios" , " android" )]
22+ [string []] $MultiTarget = @ (" uwp" , " wasdk" , " wpf" , " wasm" , " linuxgtk" , " macos" , " ios" , " android" )
1923)
2024
2125$preWorkingDir = $pwd ;
@@ -29,56 +33,31 @@ Set-Location $preWorkingDir;
2933# Insert csproj file name.
3034$csprojFileName = [System.IO.Path ]::GetFileName($relativeProjectPath );
3135$templateContents = $templateContents -replace [regex ]::escape($projectFileNamePlaceholder ), $csprojFileName ;
36+ $projectName = (Get-Item (Split-Path - Parent $projectPath )).Name;
3237
3338# Insert project directory
3439$projectDirectoryRelativeToRoot = [System.IO.Path ]::GetDirectoryName($relativeProjectPath ).TrimStart(' .' ).TrimStart(' \' );
3540$templateContents = $templateContents -replace [regex ]::escape($projectRootPlaceholder ), " $projectDirectoryRelativeToRoot " ;
3641
37- function LoadMultiTargetsFrom ([string ] $path ) {
38- $fileContents = " " ;
39-
40- # If file does not exist
41- if ($false -eq (Test-Path - Path $path - PathType Leaf)) {
42- # Load first available default
43- foreach ($fallbackPath in $multiTargetFallbackPropsPath ) {
44- if (Test-Path $fallbackPath ) {
45- $fileContents = Get-Content $fallbackPath - ErrorAction Stop;
46- break ;
47- }
48- }
49- }
50- else {
51- # Load requested file
52- $fileContents = Get-Content $path - ErrorAction Stop;
53- }
54-
55- # Parse file contents
56- $regex = Select-String - Pattern ' <MultiTarget>(.+?)<\/MultiTarget>' - InputObject $fileContents ;
57-
58- if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2 ) {
59- Write-Error " Couldn't get MultiTarget property from $path " ;
60- exit (-1 );
61- }
62-
63- return $regex.Matches.Groups [1 ].Value;
64- }
65-
6642# Load multitarget preferences for project
67- $multiTargets = LoadMultiTargetsFrom( " $ ( [ System.IO.Path ]::GetDirectoryName( $projectPath ) ) \MultiTarget.props " ) ;
68-
43+ $multiTargets = & $PSScriptRoot \GetMultiTargets.ps1 - ComponentName $projectName - ErrorAction Stop ;
44+
6945$templateContents = $templateContents -replace [regex ]::escape(" [IntendedTargets]" ), $multiTargets ;
70-
7146$multiTargets = $multiTargets.Split (' ;' );
72- Write-Host " Generating project references for $ ( [System.IO.Path ]::GetFileNameWithoutExtension($csprojFileName )) : $ ( $multiTargets -Join ' , ' ) "
7347
74- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetWasm]" ), " '$ ( $multiTargets.Contains (" wasm" ).ToString().ToLower()) '" ;
75- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetUwp]" ), " '$ ( $multiTargets.Contains (" uwp" ).ToString().ToLower()) '" ;
76- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetWasdk]" ), " '$ ( $multiTargets.Contains (" wasdk" ).ToString().ToLower()) '" ;
77- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetWpf]" ), " '$ ( $multiTargets.Contains (" wpf" ).ToString().ToLower()) '" ;
78- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetLinuxGtk]" ), " '$ ( $multiTargets.Contains (" linuxgtk" ).ToString().ToLower()) '" ;
79- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetMacOS]" ), " '$ ( $multiTargets.Contains (" macos" ).ToString().ToLower()) '" ;
80- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetiOS]" ), " '$ ( $multiTargets.Contains (" ios" ).ToString().ToLower()) '" ;
81- $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetDroid]" ), " '$ ( $multiTargets.Contains (" android" ).ToString().ToLower()) '" ;
48+ function ShouldMultiTarget ([string ] $target ) {
49+ return ($multiTargets.Contains ($target ) -and $MultiTarget.Contains ($target )).ToString().ToLower()
50+ }
51+
52+ Write-Host " Generating project references for $ ( [System.IO.Path ]::GetFileNameWithoutExtension($csprojFileName )) : $ ( $multiTargets -Join ' , ' ) "
53+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetWasm]" ), " '$ ( ShouldMultiTarget " wasm" ) '" ;
54+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetUwp]" ), " '$ ( ShouldMultiTarget " uwp" ) '" ;
55+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetWasdk]" ), " '$ ( ShouldMultiTarget " wasdk" ) '" ;
56+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetWpf]" ), " '$ ( ShouldMultiTarget " wpf" ) '" ;
57+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetLinuxGtk]" ), " '$ ( ShouldMultiTarget " linuxgtk" ) '" ;
58+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetMacOS]" ), " '$ ( ShouldMultiTarget " macos" ) '" ;
59+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetiOS]" ), " '$ ( ShouldMultiTarget " ios" ) '" ;
60+ $templateContents = $templateContents -replace [regex ]::escape(" [CanTargetDroid]" ), " '$ ( ShouldMultiTarget " droid" ) '" ;
8261
8362# Save to disk
8463Set-Content - Path $outputPath - Value $templateContents ;
0 commit comments