5
5
[Parameter (HelpMessage = " A path to a .props file where generated content should be saved to." , Mandatory = $true )]
6
6
[string ]$outputPath ,
7
7
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." )]
9
9
[string ]$templatePath = " $PSScriptRoot /MultiTargetAwareProjectReference.props.template" ,
10
10
11
11
[Parameter (HelpMessage = " The path to the props file that contains the default MultiTarget values." )]
@@ -15,7 +15,11 @@ Param (
15
15
[string ]$projectFileNamePlaceholder = " [ProjectFileName]" ,
16
16
17
17
[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" )
19
23
)
20
24
21
25
$preWorkingDir = $pwd ;
@@ -29,56 +33,31 @@ Set-Location $preWorkingDir;
29
33
# Insert csproj file name.
30
34
$csprojFileName = [System.IO.Path ]::GetFileName($relativeProjectPath );
31
35
$templateContents = $templateContents -replace [regex ]::escape($projectFileNamePlaceholder ), $csprojFileName ;
36
+ $projectName = (Get-Item (Split-Path - Parent $projectPath )).Name;
32
37
33
38
# Insert project directory
34
39
$projectDirectoryRelativeToRoot = [System.IO.Path ]::GetDirectoryName($relativeProjectPath ).TrimStart(' .' ).TrimStart(' \' );
35
40
$templateContents = $templateContents -replace [regex ]::escape($projectRootPlaceholder ), " $projectDirectoryRelativeToRoot " ;
36
41
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
-
66
42
# 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
+
69
45
$templateContents = $templateContents -replace [regex ]::escape(" [IntendedTargets]" ), $multiTargets ;
70
-
71
46
$multiTargets = $multiTargets.Split (' ;' );
72
- Write-Host " Generating project references for $ ( [System.IO.Path ]::GetFileNameWithoutExtension($csprojFileName )) : $ ( $multiTargets -Join ' , ' ) "
73
47
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" ) '" ;
82
61
83
62
# Save to disk
84
63
Set-Content - Path $outputPath - Value $templateContents ;
0 commit comments