11Param (
2- [Parameter (HelpMessage = " The full path of the csproj to generated references to." , Mandatory = $true )]
2+ [Parameter (HelpMessage = " The full path of the csproj or projitems to generate a reference to." , Mandatory = $true )]
33 [string ]$projectPath ,
44
5- [Parameter (HelpMessage = " A path to a .props file where generated content should be saved to." , Mandatory = $true )]
5+ [Parameter (HelpMessage = " A path to where the generated .props file containing the reference should be saved to." , Mandatory = $true )]
66 [string ]$outputPath ,
77
88 [Parameter (HelpMessage = " The path to the template used to generate the props file." )]
9- [string ]$templatePath = " $PSScriptRoot /MultiTargetAwareProjectReference.props.template " ,
9+ [string ]$templatePath ,
1010
1111 [Parameter (HelpMessage = " The placeholder text to replace when inserting the project file name into the template." )]
1212 [string ]$projectFileNamePlaceholder = " [ProjectFileName]" ,
@@ -20,6 +20,16 @@ Param (
2020 [string []] $MultiTargets = @ (" uwp" , " wasdk" , " wpf" , " wasm" , " linuxgtk" , " macos" , " ios" , " android" , " netstandard" )
2121)
2222
23+ if ($projectPath.EndsWith (" .projitems" )) {
24+ $templatePath = " $PSScriptRoot /MultiTargetAwareSharedProjectImport.props.template"
25+ } elseif ($projectPath.EndsWith (" .csproj" )) {
26+ $templatePath = " $PSScriptRoot /MultiTargetAwareProjectReference.props.template" ;
27+
28+ } else {
29+ Write-Error " The specified project path is not a valid csproj or projitems file: $projectPath " ;
30+ exit (-1 );
31+ }
32+
2333$templateContents = Get-Content - Path $templatePath ;
2434
2535$preWorkingDir = $pwd ;
@@ -29,9 +39,9 @@ $relativeProjectPath = Resolve-Path -Relative -Path $projectPath
2939
3040Set-Location $preWorkingDir ;
3141
32- # Insert csproj file name.
33- $csprojFileName = [System.IO.Path ]::GetFileName($projectPath );
34- $templateContents = $templateContents -replace [regex ]::escape($projectFileNamePlaceholder ), $csprojFileName ;
42+ # Insert project file name.
43+ $projectFileName = [System.IO.Path ]::GetFileName($projectPath );
44+ $templateContents = $templateContents -replace [regex ]::escape($projectFileNamePlaceholder ), $projectFileName ;
3545
3646# Insert component directory
3747$componentDirectoryRelativeToRoot = [System.IO.Path ]::GetDirectoryName($relativeProjectPath ).TrimStart(' .' ).TrimStart(' \' );
@@ -67,7 +77,7 @@ function ShouldMultiTargetMsBuildValue([string] $target) {
6777$targeted = @ (" uwp" , " wasdk" , " wpf" , " wasm" , " linuxgtk" , " macos" , " ios" , " android" , " netstandard" ).Where ({ ShouldMultiTarget $_ })
6878
6979if ($targeted.Count -gt 0 ) {
70- Write-Host " Generating project references for $ ( [System.IO.Path ]::GetFileNameWithoutExtension($csprojFileName )) : $ ( $targeted -Join ' , ' ) "
80+ Write-Host " Generating project references for $ ( [System.IO.Path ]::GetFileNameWithoutExtension($projectFileName )) : $ ( $targeted -Join ' , ' ) "
7181}
7282
7383$templateContents = $templateContents -replace [regex ]::escape(" [CanTargetWasm]" ), " '$ ( ShouldMultiTargetMsBuildValue " wasm" ) '" ;
0 commit comments