From a3817e6d65329af6c98d2ccf88782d74f24a12e2 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Thu, 1 Dec 2022 11:02:35 -0600 Subject: [PATCH 01/28] Refactored and consolidated MultiTargeting features. Adding dynamic multitargeting (WIP) --- .gitignore | 2 +- DiscoverSamples.ps1 | 104 ------------------ GenerateAllSolution.ps1 | 7 +- common/GenerateVSCodeLaunchConfig.ps1 | 62 +++++++++++ common/Labs.SampleRefs.props.template | 11 -- ...lGeneratedProjectReferences.props.template | 19 ++++ common/MultiTarget/Defaults.props | 5 + .../GenerateAllProjectReferences.ps1 | 44 ++++++++ ...eMultiTargetAwareProjectReferenceProps.ps1 | 28 +++++ .../MultiTarget.props} | 22 +++- ...TargetAwareProjectReference.props.template | 33 ++++++ ...Sample.props => SampleProjectConfig.props} | 0 common/Scripts/UseUnoWinUI.ps1 | 2 +- .../CanvasLayout.Samples.csproj | 2 +- ...nityToolkit.Labs.WinUI.CanvasLayout.csproj | 2 +- .../CanvasView.Samples.csproj | 2 +- ...munityToolkit.Labs.WinUI.CanvasView.csproj | 2 +- .../RivePlayer.Samples.csproj | 2 +- ...yToolkit.Labs.WinUI.Rive.RivePlayer.csproj | 2 +- .../SettingsControls.Samples.csproj | 2 +- ...Toolkit.Labs.WinUI.SettingsControls.csproj | 2 +- .../SizerBase.Samples.csproj | 2 +- ...mmunityToolkit.Labs.WinUI.SizerBase.csproj | 2 +- ...tackedNotificationsBehavior.Samples.csproj | 2 +- ....WinUI.StackedNotificationsBehavior.csproj | 2 +- .../src/MultiTarget.props | 9 ++ .../CommunityToolkit.Labs.Droid.csproj | 2 +- .../CommunityToolkit.Labs.Skia.Gtk.csproj | 2 +- .../CommunityToolkit.Labs.Skia.WPF.csproj | 2 +- .../CommunityToolkit.Labs.Uwp.csproj | 2 +- .../CommunityToolkit.Labs.Wasm.csproj | 2 +- .../CommunityToolkit.Labs.WinAppSdk.csproj | 2 +- .../CommunityToolkit.Labs.iOS.csproj | 2 +- .../CommunityToolkit.Labs.macOS.csproj | 2 +- .../ProjectTemplate.Samples.csproj | 2 +- ...yToolkit.Labs.WinUI.ProjectTemplate.csproj | 2 +- .../CommunityToolkit.Labs.Tests.Uwp.csproj | 2 +- ...mmunityToolkit.Labs.Tests.WinAppSdk.csproj | 2 +- 38 files changed, 248 insertions(+), 148 deletions(-) delete mode 100644 DiscoverSamples.ps1 create mode 100644 common/GenerateVSCodeLaunchConfig.ps1 delete mode 100644 common/Labs.SampleRefs.props.template create mode 100644 common/MultiTarget/AllGeneratedProjectReferences.props.template create mode 100644 common/MultiTarget/Defaults.props create mode 100644 common/MultiTarget/GenerateAllProjectReferences.ps1 create mode 100644 common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 rename common/{Labs.MultiTarget.props => MultiTarget/MultiTarget.props} (68%) create mode 100644 common/MultiTarget/MultiTargetAwareProjectReference.props.template rename common/{Labs.Sample.props => SampleProjectConfig.props} (100%) create mode 100644 labs/StackedNotificationsBehavior/src/MultiTarget.props diff --git a/.gitignore b/.gitignore index f1f0f0adc..1487f162e 100644 --- a/.gitignore +++ b/.gitignore @@ -356,4 +356,4 @@ MigrationBackup/ # Community Toolkit Labs generated files Toolkit.Labs.All.sln -Labs.SampleRefs.props +common/MultiTarget/Generated/** diff --git a/DiscoverSamples.ps1 b/DiscoverSamples.ps1 deleted file mode 100644 index cc12deb7f..000000000 --- a/DiscoverSamples.ps1 +++ /dev/null @@ -1,104 +0,0 @@ -Param ( - [Parameter(HelpMessage = "Disables suppressing changes to the ./.vscode/launch.json file in git, allowing changes to be committed.")] - [switch]$allowGitChanges = $false -) - -$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]" -$sampleRefsPropsTemplatePath = "$PSScriptRoot/common/Labs.SampleRefs.props.template"; -$generatedSampleRefsPropsPath = "$PSScriptRoot/common/Labs.SampleRefs.props"; - -function CreateVsCodeLaunchConfigJson { - param ( - [string]$projectName - ) - - return "{ - `"name`": `"$projectName`", - `"type`": `"coreclr`", - `"request`": `"launch`", - `"program`": `"dotnet`", - `"args`": [ - `"run`", - `"build`", - `"/r`", - `"/p:UnoSourceGeneratorUseGenerationHost=true`", - `"/p:UnoSourceGeneratorUseGenerationController=false`", - `"/p:UnoRemoteControlPort=443`", - `"--project=`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm/$projectName.Wasm.csproj`" - ], - `"presentation`": { - `"group`": `"2`" - }, - `"cwd`": `"`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm`" - }"; -} - -# Execute ProjectReference generation for all heads -$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath; -Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath"; - -# Add sample projects -foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path "$PSScriptRoot/labs/*/samples/*.Samples/*.Samples.csproj") { - $relativePath = Resolve-Path -Relative -Path $sampleProjectPath; - $relativePath = $relativePath.TrimStart('.\'); - $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); - - Write-Host "Adding $projectName to project references"; - - $projectReferenceDefinition = ""; - - $sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + " - " + $projectReferenceDefinition); -} - -# Add library projects -foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path "$PSScriptRoot/labs/*/src/*.csproj") { - $relativePath = Resolve-Path -Relative -Path $sampleProjectPath; - $relativePath = $relativePath.TrimStart('.\'); - $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); - - Write-Host "Adding $projectName to project references"; - - $projectReferenceDefinition = ""; - - $sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + " - " + $projectReferenceDefinition); -} - -$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ""; - -# Save -Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate; -Write-Output "Sample project references generated at $generatedSampleRefsPropsPath"; - -$launchConfigJson = Get-Content -Path "$PSScriptRoot/.vscode/launch.json"; -$launchConfig = $launchConfigJson | ConvertFrom-Json; - -# Remove all non-generated configurations -$originalConfigurations = $launchConfig.configurations; -$launchConfig.configurations = @(); -$launchConfig.configurations += $originalConfigurations[0]; -$launchConfig.configurations += $originalConfigurations[1]; - -foreach ($wasmProjectPath in Get-ChildItem -Recurse -Path "$PSScriptRoot/labs/*/samples/*.Wasm/*.Wasm.csproj") { - $projectName = [System.IO.Path]::GetFileNameWithoutExtension($wasmProjectPath) -Replace ".Wasm", ""; - Write-Host "Generating VSCode launch config for $projectName"; - - $configJson = CreateVsCodeLaunchConfigJson $projectName; - $config = $configJson | ConvertFrom-Json; - - $launchConfig.configurations += $config; -} - -if ($allowGitChanges.IsPresent) { - Write-Warning "Changes to the default launch.json in Labs can now be committed. Run this command again without the -allowGitChanges flag to disable committing further changes."; - git update-index --no-assume-unchanged ./.vscode/launch.json -} -else { - Write-Output "Changes to the default launch.json in Labs are now suppressed. To switch branches, run git reset --hard with a clean working tree. Include the -allowGitChanges flag to enable committing changes."; - git update-index --assume-unchanged $PSScriptRoot/.vscode/launch.json -} - -# Save -Set-Content -Path "$PSScriptRoot/.vscode/launch.json" -Value ($launchConfig | ConvertTo-Json -Depth 9); -Write-Output "Saved VSCode launch configs to $PSScriptRoot/.vscode/launch.json"; \ No newline at end of file diff --git a/GenerateAllSolution.ps1 b/GenerateAllSolution.ps1 index 323ee4858..2f1ac702a 100644 --- a/GenerateAllSolution.ps1 +++ b/GenerateAllSolution.ps1 @@ -4,6 +4,10 @@ Param ( [string]$UseUnoWinUI = 2 ) +# Generate required props for "All" solution. +& ./common/MultiTarget/GenerateAllProjectReferences.ps1 +& ./common/GenerateVSCodeLaunchConfig.ps1 + # Set WinUI version for Uno projects $originalWorkingDirectory = Get-Location; @@ -243,6 +247,3 @@ $solutionTemplate = $solutionTemplate -replace "(?m)^\s*`r`n", ""; # Save Set-Content -Path $generatedSolutionFilePath -Value $solutionTemplate; Write-Output "Solution generated at $generatedSolutionFilePath"; - -# Run sample discovery -& ./DiscoverSamples.ps1 diff --git a/common/GenerateVSCodeLaunchConfig.ps1 b/common/GenerateVSCodeLaunchConfig.ps1 new file mode 100644 index 000000000..2e1bf44d0 --- /dev/null +++ b/common/GenerateVSCodeLaunchConfig.ps1 @@ -0,0 +1,62 @@ +Param ( + [Parameter(HelpMessage = "Disables suppressing changes to the ./.vscode/launch.json file in git, allowing changes to be committed.")] + [switch]$allowGitChanges = $false +) + +function CreateVsCodeLaunchConfigJson { + param ( + [string]$projectName + ) + + return "{ + `"name`": `"$projectName`", + `"type`": `"coreclr`", + `"request`": `"launch`", + `"program`": `"dotnet`", + `"args`": [ + `"run`", + `"build`", + `"/r`", + `"/p:UnoSourceGeneratorUseGenerationHost=true`", + `"/p:UnoSourceGeneratorUseGenerationController=false`", + `"/p:UnoRemoteControlPort=443`", + `"--project=`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm/$projectName.Wasm.csproj`" + ], + `"presentation`": { + `"group`": `"2`" + }, + `"cwd`": `"`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm`" + }"; +} + +$launchConfigJson = Get-Content -Path "$PSScriptRoot/../.vscode/launch.json" -ErrorAction Stop; +$launchConfig = $launchConfigJson | ConvertFrom-Json; + +# Remove all non-generated configurations +$originalConfigurations = $launchConfig.configurations; +$launchConfig.configurations = @(); +$launchConfig.configurations += $originalConfigurations[0]; +$launchConfig.configurations += $originalConfigurations[1]; + +foreach ($wasmProjectPath in Get-ChildItem -Recurse -Path "$PSScriptRoot/../*/*/samples/*.Wasm/*.Wasm.csproj") { + $projectName = [System.IO.Path]::GetFileNameWithoutExtension($wasmProjectPath) -Replace ".Wasm", ""; + Write-Host "Generating VSCode launch config for $projectName"; + + $configJson = CreateVsCodeLaunchConfigJson $projectName; + $config = $configJson | ConvertFrom-Json; + + $launchConfig.configurations += $config; +} + +if ($allowGitChanges.IsPresent) { + Write-Warning "Changes to the default launch.json can now be committed. Run this command again without the -allowGitChanges flag to disable committing further changes."; + git update-index --no-assume-unchanged ./../.vscode/launch.json +} +else { + Write-Output "Changes to the default launch.json are now suppressed. To switch branches, run git reset --hard with a clean working tree. Include the -allowGitChanges flag to enable committing changes."; + git update-index --assume-unchanged $PSScriptRoot/../.vscode/launch.json +} + +# Save +Set-Content -Path "$PSScriptRoot/../.vscode/launch.json" -Value ($launchConfig | ConvertTo-Json -Depth 9); +Write-Output "Saved VSCode launch configs to $(Resolve-Path $PSScriptRoot/../.vscode/launch.json)"; \ No newline at end of file diff --git a/common/Labs.SampleRefs.props.template b/common/Labs.SampleRefs.props.template deleted file mode 100644 index 43aeba790..000000000 --- a/common/Labs.SampleRefs.props.template +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - $(DefineConstants);LABS_ALL_SAMPLES - - - [TemplatedSampleProjectReferences] - - \ No newline at end of file diff --git a/common/MultiTarget/AllGeneratedProjectReferences.props.template b/common/MultiTarget/AllGeneratedProjectReferences.props.template new file mode 100644 index 000000000..bad835e12 --- /dev/null +++ b/common/MultiTarget/AllGeneratedProjectReferences.props.template @@ -0,0 +1,19 @@ + + + + + + $(DefineConstants);LABS_ALL_SAMPLES + + [ProjectReferenceImports] + + + + + + + diff --git a/common/MultiTarget/Defaults.props b/common/MultiTarget/Defaults.props new file mode 100644 index 000000000..5b1f78d08 --- /dev/null +++ b/common/MultiTarget/Defaults.props @@ -0,0 +1,5 @@ + + + uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; + + \ No newline at end of file diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 new file mode 100644 index 000000000..66dd0e94d --- /dev/null +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -0,0 +1,44 @@ +Param ( + [Parameter(HelpMessage = "The directory where props files for discovered projects should be saved.")] + [string]$projectPropsOutputDir = "$PSScriptRoot/Generated", + + [Parameter(HelpMessage = "The path to a props file that will be populated with project imports for all discovered projects.")] + [string]$outputPath = "$projectPropsOutputDir/AllGeneratedProjectReferences.props", + + [Parameter(HelpMessage = "The directories to scan for projects. Supports wildcards.")] + [string[]]$projectDirectories = @("$PSScriptRoot/../../*/*/samples/*.Samples/*.Samples.csproj", "$PSScriptRoot/../../*/*/src/*.csproj"), + + [Parameter(HelpMessage = "The path to the template used to generate the props file.")] + [string]$templatePath = "$PSScriptRoot/AllGeneratedProjectReferences.props.template", + + [Parameter(HelpMessage = "The placeholder text to replace when inserting the project file name into the template.")] + [string]$projectReferencesDefinitionMarker = "[ProjectReferenceImports]" +) + +# Load template +$templateContents = Get-Content -Path $templatePath; +Write-Output "Loaded template from $(Resolve-Path $templatePath)"; + +# Discover projects in provided paths +foreach ($path in $projectDirectories) { + foreach ($projectPath in Get-ChildItem -Recurse -Path $path) { + $relativePath = Resolve-Path -Relative -Path $projectPath; + $relativePath = $relativePath.TrimStart('.\'); + $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); + + Write-Host "Generating project references for $projectName"; + + & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 $projectPath "$projectPropsOutputDir/$projectName.props"; + $projectReferenceDefinition = ""; + + $templateContents = $templateContents -replace [regex]::escape($projectReferencesDefinitionMarker), ($projectReferencesDefinitionMarker + " + " + $projectReferenceDefinition); + } +} + +# Remove placeholder from template +$templateContents = $templateContents -replace [regex]::escape($projectReferencesDefinitionMarker), ""; + +# Save +Set-Content -Path $outputPath -Value $templateContents; +Write-Output "Project references generated at $(Resolve-Path $outputPath)"; diff --git a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 new file mode 100644 index 000000000..1b162b9ae --- /dev/null +++ b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -0,0 +1,28 @@ +Param ( + [Parameter(HelpMessage = "The full path of the csproj to generated references to.", Mandatory = $true)] + [string]$projectPath, + + [Parameter(HelpMessage = "A path to a .props file where generated content should be saved to.", Mandatory = $true)] + [string]$outputPath, + + [Parameter(HelpMessage = "The path to the template used to generate the props file.")] + [string]$templatePath = "$PSScriptRoot/MultiTargetAwareProjectReference.props.template", + + [Parameter(HelpMessage = "The placeholder text to replace when inserting the project file name into the template.")] + [string]$projectFileNamePlaceholder = "[ProjectFileName]", + + [Parameter(HelpMessage = "The placeholder text to replace when inserting the project path into the template.")] + [string]$projectRootPlaceholder = "[ProjectRoot]" +) + +$relativeProjectPath = (Resolve-Path -Path $projectPath); +$templateContents = Get-Content -Path $templatePath; + +# Insert csproj file name. +$templateContents = $templateContents -replace [regex]::escape($projectFileNamePlaceholder), ([System.IO.Path]::GetFileName(($relativeProjectPath))); + +# Insert project directory +$templateContents = $templateContents -replace [regex]::escape($projectRootPlaceholder), ([System.IO.Path]::GetDirectoryName(($relativeProjectPath))); + +# Save to disk +Set-Content -Path $outputPath -Value $templateContents; \ No newline at end of file diff --git a/common/Labs.MultiTarget.props b/common/MultiTarget/MultiTarget.props similarity index 68% rename from common/Labs.MultiTarget.props rename to common/MultiTarget/MultiTarget.props index 841cd5b20..283b2aa27 100644 --- a/common/Labs.MultiTarget.props +++ b/common/MultiTarget/MultiTarget.props @@ -1,11 +1,22 @@ + uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; + + + + $(NetStandardCommonTargetFramework); $(UwpTargetFramework); @@ -25,10 +36,12 @@ 10.0.17763.0 10.0.19041.0 + WMC1006;CS8034; + @@ -46,6 +59,7 @@ + diff --git a/common/MultiTarget/MultiTargetAwareProjectReference.props.template b/common/MultiTarget/MultiTargetAwareProjectReference.props.template new file mode 100644 index 000000000..d455d00fe --- /dev/null +++ b/common/MultiTarget/MultiTargetAwareProjectReference.props.template @@ -0,0 +1,33 @@ + + + + + + + [ProjectFileName] + [ProjectRoot] + + + + + + + + $(MultiTargetDefaults) + + + + + + + diff --git a/common/Labs.Sample.props b/common/SampleProjectConfig.props similarity index 100% rename from common/Labs.Sample.props rename to common/SampleProjectConfig.props diff --git a/common/Scripts/UseUnoWinUI.ps1 b/common/Scripts/UseUnoWinUI.ps1 index 3ab9cf4c4..9c68c2036 100644 --- a/common/Scripts/UseUnoWinUI.ps1 +++ b/common/Scripts/UseUnoWinUI.ps1 @@ -58,4 +58,4 @@ else { Write-Output "Changes to the default Uno package settings in Labs are now suppressed.`r`nTo switch branches, run `"git reset --hard`" with a clean working tree."; } -Write-Output "Done" \ No newline at end of file +Write-Output "Done, switched to WinUI $winUIMajorVersion" \ No newline at end of file diff --git a/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj b/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj index d9dadd648..92eb7d9dd 100644 --- a/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj +++ b/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj @@ -5,7 +5,7 @@ - + diff --git a/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj b/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj index f0b2f5dfa..7312f8cec 100644 --- a/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj +++ b/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.CanvasLayoutRns diff --git a/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj b/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj index 4838a1389..d53789003 100644 --- a/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj +++ b/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj @@ -5,7 +5,7 @@ - + diff --git a/labs/CanvasView/src/CommunityToolkit.Labs.WinUI.CanvasView.csproj b/labs/CanvasView/src/CommunityToolkit.Labs.WinUI.CanvasView.csproj index f22040495..8187de720 100644 --- a/labs/CanvasView/src/CommunityToolkit.Labs.WinUI.CanvasView.csproj +++ b/labs/CanvasView/src/CommunityToolkit.Labs.WinUI.CanvasView.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.CanvasViewRns diff --git a/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj b/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj index dd77a1ca9..6dcebe768 100644 --- a/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj +++ b/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj @@ -5,7 +5,7 @@ - + diff --git a/labs/RivePlayer/src/CommunityToolkit.Labs.WinUI.Rive.RivePlayer.csproj b/labs/RivePlayer/src/CommunityToolkit.Labs.WinUI.Rive.RivePlayer.csproj index 89248f696..715cc6026 100644 --- a/labs/RivePlayer/src/CommunityToolkit.Labs.WinUI.Rive.RivePlayer.csproj +++ b/labs/RivePlayer/src/CommunityToolkit.Labs.WinUI.Rive.RivePlayer.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.Rive diff --git a/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj b/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj index a61bfb645..8a0f03ae7 100644 --- a/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj +++ b/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj @@ -5,7 +5,7 @@ - + diff --git a/labs/SettingsControls/src/CommunityToolkit.Labs.WinUI.SettingsControls.csproj b/labs/SettingsControls/src/CommunityToolkit.Labs.WinUI.SettingsControls.csproj index f235a149f..b51459490 100644 --- a/labs/SettingsControls/src/CommunityToolkit.Labs.WinUI.SettingsControls.csproj +++ b/labs/SettingsControls/src/CommunityToolkit.Labs.WinUI.SettingsControls.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.SettingsControlsRns diff --git a/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj b/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj index 5b460836d..0acda2fdf 100644 --- a/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj +++ b/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj @@ -5,7 +5,7 @@ - + diff --git a/labs/SizerBase/src/CommunityToolkit.Labs.WinUI.SizerBase.csproj b/labs/SizerBase/src/CommunityToolkit.Labs.WinUI.SizerBase.csproj index 328226ea4..11cecb96c 100644 --- a/labs/SizerBase/src/CommunityToolkit.Labs.WinUI.SizerBase.csproj +++ b/labs/SizerBase/src/CommunityToolkit.Labs.WinUI.SizerBase.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.SizerBaseRns diff --git a/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj b/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj index a57abbd18..2ccfdbd1f 100644 --- a/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj +++ b/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj @@ -5,7 +5,7 @@ - + diff --git a/labs/StackedNotificationsBehavior/src/CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj b/labs/StackedNotificationsBehavior/src/CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj index 3734bd8f5..9a50e72c0 100644 --- a/labs/StackedNotificationsBehavior/src/CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj +++ b/labs/StackedNotificationsBehavior/src/CommunityToolkit.Labs.WinUI.StackedNotificationsBehavior.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.StackedNotificationsBehaviorRns diff --git a/labs/StackedNotificationsBehavior/src/MultiTarget.props b/labs/StackedNotificationsBehavior/src/MultiTarget.props new file mode 100644 index 000000000..bbe050db8 --- /dev/null +++ b/labs/StackedNotificationsBehavior/src/MultiTarget.props @@ -0,0 +1,9 @@ + + + + uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; + + \ No newline at end of file diff --git a/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj b/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj index e2ca8e27e..203185f9c 100644 --- a/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj +++ b/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj @@ -30,7 +30,7 @@ - + Debug diff --git a/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj b/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj index 1ad6a213d..92cc6a5f2 100644 --- a/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj +++ b/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj @@ -27,7 +27,7 @@ - + WinExe diff --git a/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj b/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj index bf587cf0e..e5301e20d 100644 --- a/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj +++ b/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj @@ -28,7 +28,7 @@ - + diff --git a/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj b/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj index d17f7aaa8..b3a3049eb 100644 --- a/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj +++ b/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj @@ -29,7 +29,7 @@ - + CommunityToolkit.Labs.Uwp diff --git a/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj b/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj index 9d9ef6ae3..003afef90 100644 --- a/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj +++ b/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj @@ -28,7 +28,7 @@ - + diff --git a/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj b/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj index 5629ae128..0477a4584 100644 --- a/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj +++ b/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj @@ -26,7 +26,7 @@ - + CommunityToolkit.Labs.WinAppSdk diff --git a/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj b/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj index 04536b3de..65d05b6ca 100644 --- a/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj +++ b/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj @@ -30,7 +30,7 @@ - + Debug diff --git a/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj b/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj index 118786b21..7e6db8880 100644 --- a/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj +++ b/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj @@ -30,7 +30,7 @@ - + Debug diff --git a/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj b/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj index 7c3187b97..db7a69e30 100644 --- a/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj +++ b/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj @@ -5,7 +5,7 @@ - + diff --git a/template/lab/src/CommunityToolkit.Labs.WinUI.ProjectTemplate.csproj b/template/lab/src/CommunityToolkit.Labs.WinUI.ProjectTemplate.csproj index b84b68021..9b0aad71f 100644 --- a/template/lab/src/CommunityToolkit.Labs.WinUI.ProjectTemplate.csproj +++ b/template/lab/src/CommunityToolkit.Labs.WinUI.ProjectTemplate.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.ProjectTemplateRns diff --git a/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj b/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj index 3e86f32a5..07be85d6b 100644 --- a/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj +++ b/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj @@ -61,7 +61,7 @@ - + diff --git a/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj b/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj index 4e61f5ca8..c330fb365 100644 --- a/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj +++ b/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj @@ -41,5 +41,5 @@ - + From a4d5df7e46d50ffc56b78ea348baae3528abeec7 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Thu, 1 Dec 2022 12:23:49 -0600 Subject: [PATCH 02/28] Fixed invalid prop references --- .../samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj | 2 +- .../src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj | 2 +- .../samples/CanvasView.Samples/CanvasView.Samples.csproj | 2 +- .../samples/RivePlayer.Samples/RivePlayer.Samples.csproj | 2 +- .../SettingsControls.Samples/SettingsControls.Samples.csproj | 2 +- .../samples/SizerBase.Samples/SizerBase.Samples.csproj | 2 +- .../StackedNotificationsBehavior.Samples.csproj | 2 +- .../ProjectTemplate.Samples/ProjectTemplate.Samples.csproj | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj b/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj index 92eb7d9dd..c5985646e 100644 --- a/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj +++ b/labs/CanvasLayout/samples/CanvasLayout.Samples/CanvasLayout.Samples.csproj @@ -8,7 +8,7 @@ - + CanvasLayoutExperiment.Samples diff --git a/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj b/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj index 7312f8cec..535f3ef02 100644 --- a/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj +++ b/labs/CanvasLayout/src/CommunityToolkit.Labs.WinUI.CanvasLayout.csproj @@ -7,7 +7,7 @@ - + CommunityToolkit.Labs.WinUI.CanvasLayoutRns diff --git a/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj b/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj index d53789003..883248489 100644 --- a/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj +++ b/labs/CanvasView/samples/CanvasView.Samples/CanvasView.Samples.csproj @@ -8,7 +8,7 @@ - + CanvasViewExperiment.Samples diff --git a/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj b/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj index 6dcebe768..7870a3258 100644 --- a/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj +++ b/labs/RivePlayer/samples/RivePlayer.Samples/RivePlayer.Samples.csproj @@ -8,7 +8,7 @@ - + RivePlayerExperiment.Samples diff --git a/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj b/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj index 8a0f03ae7..4bf0146f4 100644 --- a/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj +++ b/labs/SettingsControls/samples/SettingsControls.Samples/SettingsControls.Samples.csproj @@ -8,7 +8,7 @@ - + SettingsControlsExperiment.Samples diff --git a/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj b/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj index 0acda2fdf..2e181adcf 100644 --- a/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj +++ b/labs/SizerBase/samples/SizerBase.Samples/SizerBase.Samples.csproj @@ -8,7 +8,7 @@ - + SizerBaseExperiment.Samples diff --git a/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj b/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj index 2ccfdbd1f..eda1d7119 100644 --- a/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj +++ b/labs/StackedNotificationsBehavior/samples/StackedNotificationsBehavior.Samples/StackedNotificationsBehavior.Samples.csproj @@ -8,7 +8,7 @@ - + StackedNotificationsBehaviorExperiment.Samples diff --git a/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj b/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj index db7a69e30..682b5a350 100644 --- a/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj +++ b/template/lab/samples/ProjectTemplate.Samples/ProjectTemplate.Samples.csproj @@ -8,7 +8,7 @@ - + ProjectTemplateExperiment.Samples From be5b05b007cc0a7eba3bbd81758f58ad9aa8d342 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 2 Dec 2022 14:39:16 -0600 Subject: [PATCH 03/28] WIP fixing MultiTargetAwareProjectReference --- common/MultiTarget/Defaults.props | 2 +- ...eMultiTargetAwareProjectReferenceProps.ps1 | 44 +++++++++++++++++-- common/MultiTarget/MultiTarget.props | 17 ++----- ...TargetAwareProjectReference.props.template | 27 +++++------- 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/common/MultiTarget/Defaults.props b/common/MultiTarget/Defaults.props index 5b1f78d08..86e5e82f7 100644 --- a/common/MultiTarget/Defaults.props +++ b/common/MultiTarget/Defaults.props @@ -1,5 +1,5 @@ - uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; + uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; \ No newline at end of file diff --git a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 index 1b162b9ae..6c0e8678b 100644 --- a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 +++ b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -8,6 +8,9 @@ Param ( [Parameter(HelpMessage = "The path to the template used to generate the props file.")] [string]$templatePath = "$PSScriptRoot/MultiTargetAwareProjectReference.props.template", + [Parameter(HelpMessage = "The path to the props file that contains the default MultiTarget values.")] + [string]$multiTargetDefaultPropsPath = "$PSScriptRoot/Defaults.props", + [Parameter(HelpMessage = "The placeholder text to replace when inserting the project file name into the template.")] [string]$projectFileNamePlaceholder = "[ProjectFileName]", @@ -19,10 +22,45 @@ $relativeProjectPath = (Resolve-Path -Path $projectPath); $templateContents = Get-Content -Path $templatePath; # Insert csproj file name. -$templateContents = $templateContents -replace [regex]::escape($projectFileNamePlaceholder), ([System.IO.Path]::GetFileName(($relativeProjectPath))); +$csprojFileName = [System.IO.Path]::GetFileName($relativeProjectPath); +$templateContents = $templateContents -replace [regex]::escape($projectFileNamePlaceholder), $csprojFileName; # Insert project directory -$templateContents = $templateContents -replace [regex]::escape($projectRootPlaceholder), ([System.IO.Path]::GetDirectoryName(($relativeProjectPath))); +$projectDirectory = [System.IO.Path]::GetDirectoryName($relativeProjectPath); +$templateContents = $templateContents -replace [regex]::escape($projectRootPlaceholder), $projectDirectory; + + +function LoadMultiTargetsFrom([string] $path) { + $fileContents = ""; + + # If file does not exist + if ((Test-Path $path) -eq $false) + { + # Load defaults + $fileContents = Get-Content $multiTargetDefaultPropsPath -ErrorAction Stop; + } + else + { + # Load requested file + $fileContents = Get-Content $path -ErrorAction Stop; + } + + # Parse file contents + $regex = Select-String -Pattern '(.+?)<\/MultiTarget>' -InputObject $fileContents; + + if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2) { + Write-Error "Couldn't get MultiTarget property from $path"; + exit(-1); + } + + return $regex.Matches.Groups[1].Value; +} + +# Load multitarget preferences for project +$multiTargets = LoadMultiTargetsFrom("$projectDirectory\MultiTargets.props"); + + +$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), $multiTargets.Contains("wasm").ToString(); # Save to disk -Set-Content -Path $outputPath -Value $templateContents; \ No newline at end of file +Set-Content -Path $outputPath -Value $templateContents; diff --git a/common/MultiTarget/MultiTarget.props b/common/MultiTarget/MultiTarget.props index 283b2aa27..f04183d18 100644 --- a/common/MultiTarget/MultiTarget.props +++ b/common/MultiTarget/MultiTarget.props @@ -5,26 +5,17 @@ Used by tooling to dynamically generate optimized solutions, build scripts, and nuget packages based on preferences and capabilities of available projects. --> uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; - + $(TargetFrameworks);$(WinAppSdkTargetFramework) - - - - $(NetStandardCommonTargetFramework); - $(UwpTargetFramework); - $(WinAppSdkTargetFramework); - $(MacOSLibTargetFramework); - $(iOSLibTargetFramework); - $(AndroidLibTargetFramework); - + $(TargetFrameworks);$(AndroidLibTargetFramework) true true diff --git a/common/MultiTarget/MultiTargetAwareProjectReference.props.template b/common/MultiTarget/MultiTargetAwareProjectReference.props.template index d455d00fe..948be6072 100644 --- a/common/MultiTarget/MultiTargetAwareProjectReference.props.template +++ b/common/MultiTarget/MultiTargetAwareProjectReference.props.template @@ -6,28 +6,23 @@ - - [ProjectFileName] - [ProjectRoot] - - - + - + $(MultiTargetDefaults) - - + + From 6f37b8ba16f554618fd0946fdfb6c2d5bc6a6e5d Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 2 Dec 2022 15:41:53 -0600 Subject: [PATCH 04/28] Completed dynamic multitargeting implementation --- ...nerateMultiTargetAwareProjectReferenceProps.ps1 | 14 ++++++++++---- ...MultiTargetAwareProjectReference.props.template | 11 +---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 index 6c0e8678b..e31358b56 100644 --- a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 +++ b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -29,7 +29,6 @@ $templateContents = $templateContents -replace [regex]::escape($projectFileNameP $projectDirectory = [System.IO.Path]::GetDirectoryName($relativeProjectPath); $templateContents = $templateContents -replace [regex]::escape($projectRootPlaceholder), $projectDirectory; - function LoadMultiTargetsFrom([string] $path) { $fileContents = ""; @@ -58,9 +57,16 @@ function LoadMultiTargetsFrom([string] $path) { # Load multitarget preferences for project $multiTargets = LoadMultiTargetsFrom("$projectDirectory\MultiTargets.props"); - - -$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), $multiTargets.Contains("wasm").ToString(); +$multiTargets = $multiTargets.Split(';'); + +$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$($multiTargets.Contains("wasm").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetUwp]"), "'$($multiTargets.Contains("uwp").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasdk]"), "'$($multiTargets.Contains("wasdk").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]"), "'$($multiTargets.Contains("wpf").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$($multiTargets.Contains("linuxgtk").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$($multiTargets.Contains("macos").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$($multiTargets.Contains("ios").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$($multiTargets.Contains("droid").ToString().ToLower())'"; # Save to disk Set-Content -Path $outputPath -Value $templateContents; diff --git a/common/MultiTarget/MultiTargetAwareProjectReference.props.template b/common/MultiTarget/MultiTargetAwareProjectReference.props.template index 948be6072..5464e1478 100644 --- a/common/MultiTarget/MultiTargetAwareProjectReference.props.template +++ b/common/MultiTarget/MultiTargetAwareProjectReference.props.template @@ -4,15 +4,6 @@ --> - - - - - - - - $(MultiTargetDefaults) - + ($(IsDroid) == 'true' AND [CanTargetDroid] == 'true')"> From b892efe13a9a03952efcdb48d58c030e31468917 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 2 Dec 2022 16:13:12 -0600 Subject: [PATCH 05/28] Fixed an issue where Generated folder was not created --- common/MultiTarget/GenerateAllProjectReferences.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index 66dd0e94d..447ad7af2 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -19,6 +19,8 @@ Param ( $templateContents = Get-Content -Path $templatePath; Write-Output "Loaded template from $(Resolve-Path $templatePath)"; +mkdir $projectPropsOutputDir -ErrorAction SilentlyContinue | Out-Null; + # Discover projects in provided paths foreach ($path in $projectDirectories) { foreach ($projectPath in Get-ChildItem -Recurse -Path $path) { @@ -26,7 +28,7 @@ foreach ($path in $projectDirectories) { $relativePath = $relativePath.TrimStart('.\'); $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); - Write-Host "Generating project references for $projectName"; + Write-Output "Generating project references for $projectName"; & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 $projectPath "$projectPropsOutputDir/$projectName.props"; $projectReferenceDefinition = ""; From 45110d53fad982521c73ebe23064e8116c401443 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 2 Dec 2022 16:21:56 -0600 Subject: [PATCH 06/28] Fixing bugs, cleaning up logging --- .../GenerateAllProjectReferences.ps1 | 4 +--- ...eMultiTargetAwareProjectReferenceProps.ps1 | 24 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index 447ad7af2..ba59cd149 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -27,9 +27,7 @@ foreach ($path in $projectDirectories) { $relativePath = Resolve-Path -Relative -Path $projectPath; $relativePath = $relativePath.TrimStart('.\'); $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); - - Write-Output "Generating project references for $projectName"; - + & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 $projectPath "$projectPropsOutputDir/$projectName.props"; $projectReferenceDefinition = ""; diff --git a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 index e31358b56..55be2d8ae 100644 --- a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 +++ b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -33,32 +33,32 @@ function LoadMultiTargetsFrom([string] $path) { $fileContents = ""; # If file does not exist - if ((Test-Path $path) -eq $false) - { + if ($false -eq (Test-Path -Path $path -PathType Leaf)) { # Load defaults $fileContents = Get-Content $multiTargetDefaultPropsPath -ErrorAction Stop; } - else - { + else { # Load requested file $fileContents = Get-Content $path -ErrorAction Stop; } # Parse file contents - $regex = Select-String -Pattern '(.+?)<\/MultiTarget>' -InputObject $fileContents; + $regex = Select-String -Pattern '(.+?)<\/MultiTarget>' -InputObject $fileContents; - if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2) { - Write-Error "Couldn't get MultiTarget property from $path"; - exit(-1); - } + if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2) { + Write-Error "Couldn't get MultiTarget property from $path"; + exit(-1); + } - return $regex.Matches.Groups[1].Value; + return $regex.Matches.Groups[1].Value; } # Load multitarget preferences for project -$multiTargets = LoadMultiTargetsFrom("$projectDirectory\MultiTargets.props"); +$multiTargets = LoadMultiTargetsFrom("$projectDirectory\MultiTarget.props"); $multiTargets = $multiTargets.Split(';'); +Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($multiTargets -Join ', ')" + $templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$($multiTargets.Contains("wasm").ToString().ToLower())'"; $templateContents = $templateContents -replace [regex]::escape("[CanTargetUwp]"), "'$($multiTargets.Contains("uwp").ToString().ToLower())'"; $templateContents = $templateContents -replace [regex]::escape("[CanTargetWasdk]"), "'$($multiTargets.Contains("wasdk").ToString().ToLower())'"; @@ -66,7 +66,7 @@ $templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]") $templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$($multiTargets.Contains("linuxgtk").ToString().ToLower())'"; $templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$($multiTargets.Contains("macos").ToString().ToLower())'"; $templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$($multiTargets.Contains("ios").ToString().ToLower())'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$($multiTargets.Contains("droid").ToString().ToLower())'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$($multiTargets.Contains("android").ToString().ToLower())'"; # Save to disk Set-Content -Path $outputPath -Value $templateContents; From f45612a68f5adaeac13e6958dfb5204ac85bf5dd Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 2 Dec 2022 16:31:44 -0600 Subject: [PATCH 07/28] Applying test MultiTarget value --- .../samples/RivePlayer.Samples/MultiTarget.props | 9 +++++++++ labs/RivePlayer/src/MultiTarget.props | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props create mode 100644 labs/RivePlayer/src/MultiTarget.props diff --git a/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props b/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props new file mode 100644 index 000000000..86be60134 --- /dev/null +++ b/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props @@ -0,0 +1,9 @@ + + + + uwp;wasdk;wpf;wasm; + + \ No newline at end of file diff --git a/labs/RivePlayer/src/MultiTarget.props b/labs/RivePlayer/src/MultiTarget.props new file mode 100644 index 000000000..86be60134 --- /dev/null +++ b/labs/RivePlayer/src/MultiTarget.props @@ -0,0 +1,9 @@ + + + + uwp;wasdk;wpf;wasm; + + \ No newline at end of file From a00406140746b8d939a445b0ef99c1c3ff78bbfb Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 5 Dec 2022 11:06:40 -0600 Subject: [PATCH 08/28] Skip template when generating project references --- common/MultiTarget/GenerateAllProjectReferences.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index ba59cd149..23f996c9e 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -27,6 +27,10 @@ foreach ($path in $projectDirectories) { $relativePath = Resolve-Path -Relative -Path $projectPath; $relativePath = $relativePath.TrimStart('.\'); $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); + + if ($projectName.ToLower().EndsWith("template")) { + continue; + } & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 $projectPath "$projectPropsOutputDir/$projectName.props"; $projectReferenceDefinition = ""; From 24970ac4f8c3277294f771297703119ba53c5511 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 5 Dec 2022 21:58:45 -0600 Subject: [PATCH 09/28] Added proper exclude filter to project generation script --- common/MultiTarget/GenerateAllProjectReferences.ps1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index 23f996c9e..9b74eb5b5 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -2,6 +2,9 @@ Param ( [Parameter(HelpMessage = "The directory where props files for discovered projects should be saved.")] [string]$projectPropsOutputDir = "$PSScriptRoot/Generated", + [Parameter(HelpMessage = "Filters projects that have paths which match the provided string.")] + [string]$Exclude = "*template*", + [Parameter(HelpMessage = "The path to a props file that will be populated with project imports for all discovered projects.")] [string]$outputPath = "$projectPropsOutputDir/AllGeneratedProjectReferences.props", @@ -23,14 +26,10 @@ mkdir $projectPropsOutputDir -ErrorAction SilentlyContinue | Out-Null; # Discover projects in provided paths foreach ($path in $projectDirectories) { - foreach ($projectPath in Get-ChildItem -Recurse -Path $path) { + foreach ($projectPath in Get-ChildItem -Recurse -Path $path -Exclude $Exclude) { $relativePath = Resolve-Path -Relative -Path $projectPath; $relativePath = $relativePath.TrimStart('.\'); $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); - - if ($projectName.ToLower().EndsWith("template")) { - continue; - } & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 $projectPath "$projectPropsOutputDir/$projectName.props"; $projectReferenceDefinition = ""; From 9019e20155bea8f51dcbd50d9ce82cb1c713e913 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 5 Dec 2022 22:50:50 -0600 Subject: [PATCH 10/28] Only MultiTarget functional platforms for Rive --- labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props | 2 +- labs/RivePlayer/src/MultiTarget.props | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props b/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props index 86be60134..dce54a3c7 100644 --- a/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props +++ b/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props @@ -4,6 +4,6 @@ MultiTarget is a custom property that indicates which target a project is designed to be built for / run on. Used by tooling to dynamically generate optimized solutions, build scripts, and nuget packages based on preferences and capabilities of available projects. --> - uwp;wasdk;wpf;wasm; + uwp;wasdk;wasm; \ No newline at end of file diff --git a/labs/RivePlayer/src/MultiTarget.props b/labs/RivePlayer/src/MultiTarget.props index 86be60134..dce54a3c7 100644 --- a/labs/RivePlayer/src/MultiTarget.props +++ b/labs/RivePlayer/src/MultiTarget.props @@ -4,6 +4,6 @@ MultiTarget is a custom property that indicates which target a project is designed to be built for / run on. Used by tooling to dynamically generate optimized solutions, build scripts, and nuget packages based on preferences and capabilities of available projects. --> - uwp;wasdk;wpf;wasm; + uwp;wasdk;wasm; \ No newline at end of file From 74f7b049c37b1bbcd18320b89ecef471c651048d Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Tue, 6 Dec 2022 18:39:19 -0600 Subject: [PATCH 11/28] Fixed creation of missing projectPropsOutputDir on Linux --- common/MultiTarget/GenerateAllProjectReferences.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index 9b74eb5b5..007f62ebc 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -22,7 +22,8 @@ Param ( $templateContents = Get-Content -Path $templatePath; Write-Output "Loaded template from $(Resolve-Path $templatePath)"; -mkdir $projectPropsOutputDir -ErrorAction SilentlyContinue | Out-Null; +# Create output folder if not exists +New-Item -ItemType Directory -Force -Path $projectPropsOutputDir -ErrorAction SilentlyContinue | Out-Null; # Discover projects in provided paths foreach ($path in $projectDirectories) { From a4382e72c7ff08a0891f919275318a2a101674bd Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Thu, 8 Dec 2022 11:09:42 -0600 Subject: [PATCH 12/28] Removed extraneous import --- .../MultiTarget/MultiTargetAwareProjectReference.props.template | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/MultiTarget/MultiTargetAwareProjectReference.props.template b/common/MultiTarget/MultiTargetAwareProjectReference.props.template index 5464e1478..6392adbe1 100644 --- a/common/MultiTarget/MultiTargetAwareProjectReference.props.template +++ b/common/MultiTarget/MultiTargetAwareProjectReference.props.template @@ -3,8 +3,6 @@ Adds a ProjectReference only if the referenced project indicates it can target the referencing project. --> - - Date: Thu, 8 Dec 2022 11:19:06 -0600 Subject: [PATCH 14/28] Fixed sample discovery in VSCode --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a604a5cc7..8cabf0500 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,7 +27,7 @@ "type": "PowerShell", "request": "launch", "name": "Discover samples", - "script": "${workspaceFolder}/DiscoverSamples.ps1", + "script": "${workspaceFolder}/common/MultiTarget/GenerateAllProjectReferences.ps1; ${workspaceFolder}/common/GenerateVSCodeLaunchConfig.ps1; ", "presentation": { "group": "2", "order": 2 From c90aba3ad64b88f9a2b17ef4501cc658dbf350ad Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 9 Dec 2022 15:48:01 -0600 Subject: [PATCH 15/28] Fixed conditional project references in visual studio --- ...TargetAwareProjectReference.props.template | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/common/MultiTarget/MultiTargetAwareProjectReference.props.template b/common/MultiTarget/MultiTargetAwareProjectReference.props.template index 6392adbe1..cbcf09aa9 100644 --- a/common/MultiTarget/MultiTargetAwareProjectReference.props.template +++ b/common/MultiTarget/MultiTargetAwareProjectReference.props.template @@ -4,14 +4,21 @@ --> - - - + + + + + + + + + + From 54a4afb220fc4913780360a278a3df3f0ef6545a Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 9 Dec 2022 16:31:54 -0600 Subject: [PATCH 16/28] Added missing default project identifiers --- .../CommunityToolkit.Labs.Tests.Uwp.csproj | 15 +++++++++++++++ .../CommunityToolkit.Labs.Tests.WinAppSdk.csproj | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj b/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj index 07be85d6b..e8fcd3094 100644 --- a/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj +++ b/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj @@ -6,6 +6,21 @@ true + false + false + false + false + false + false + false + true + false + false + false + false + false + false + false diff --git a/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj b/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj index c330fb365..5bfe84f2f 100644 --- a/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj +++ b/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj @@ -3,6 +3,21 @@ true + false + false + false + false + false + false + false + false + true + false + false + false + false + false + false From 452eb1ac44dae521605de5a1fb9212e521a7b7ef Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 9 Dec 2022 16:53:18 -0600 Subject: [PATCH 17/28] Updated MultiTarget description --- common/MultiTarget/MultiTarget.props | 2 +- .../samples/RivePlayer.Samples/MultiTarget.props | 8 ++++---- labs/RivePlayer/src/MultiTarget.props | 8 ++++---- labs/StackedNotificationsBehavior/src/MultiTarget.props | 4 ++-- .../samples/ProjectTemplate.Samples/MultiTarget.props | 9 +++++++++ template/lab/src/MultiTarget.props | 9 +++++++++ 6 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 template/lab/samples/ProjectTemplate.Samples/MultiTarget.props create mode 100644 template/lab/src/MultiTarget.props diff --git a/common/MultiTarget/MultiTarget.props b/common/MultiTarget/MultiTarget.props index f04183d18..a1ee39363 100644 --- a/common/MultiTarget/MultiTarget.props +++ b/common/MultiTarget/MultiTarget.props @@ -2,7 +2,7 @@ uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; diff --git a/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props b/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props index dce54a3c7..f73b29dd4 100644 --- a/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props +++ b/labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props @@ -1,9 +1,9 @@ - + uwp;wasdk;wasm; \ No newline at end of file diff --git a/labs/RivePlayer/src/MultiTarget.props b/labs/RivePlayer/src/MultiTarget.props index dce54a3c7..f73b29dd4 100644 --- a/labs/RivePlayer/src/MultiTarget.props +++ b/labs/RivePlayer/src/MultiTarget.props @@ -1,9 +1,9 @@ - + uwp;wasdk;wasm; \ No newline at end of file diff --git a/labs/StackedNotificationsBehavior/src/MultiTarget.props b/labs/StackedNotificationsBehavior/src/MultiTarget.props index bbe050db8..b11c19426 100644 --- a/labs/StackedNotificationsBehavior/src/MultiTarget.props +++ b/labs/StackedNotificationsBehavior/src/MultiTarget.props @@ -1,8 +1,8 @@ uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; diff --git a/template/lab/samples/ProjectTemplate.Samples/MultiTarget.props b/template/lab/samples/ProjectTemplate.Samples/MultiTarget.props new file mode 100644 index 000000000..b11c19426 --- /dev/null +++ b/template/lab/samples/ProjectTemplate.Samples/MultiTarget.props @@ -0,0 +1,9 @@ + + + + uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; + + \ No newline at end of file diff --git a/template/lab/src/MultiTarget.props b/template/lab/src/MultiTarget.props new file mode 100644 index 000000000..b11c19426 --- /dev/null +++ b/template/lab/src/MultiTarget.props @@ -0,0 +1,9 @@ + + + + uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; + + \ No newline at end of file From 7edbe3f06fabede2b61d0595d193be6fa0b51b64 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 12 Dec 2022 15:15:46 -0600 Subject: [PATCH 18/28] Fixed invalid path separator on Linux --- common/Scripts/UseUnoWinUI.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/Scripts/UseUnoWinUI.ps1 b/common/Scripts/UseUnoWinUI.ps1 index 9c68c2036..49eb71726 100644 --- a/common/Scripts/UseUnoWinUI.ps1 +++ b/common/Scripts/UseUnoWinUI.ps1 @@ -47,9 +47,9 @@ function ApplyWinUISwap([string] $filePath) { Write-Output "Switching to WinUI $winUIMajorVersion"; -ApplyWinUISwap $PSScriptRoot\..\Labs.Head.Uno.props -ApplyWinUISwap $PSScriptRoot\..\Labs.Uno.props -ApplyWinUISwap $PSScriptRoot\..\Labs.ProjectIdentifiers.props +ApplyWinUISwap $PSScriptRoot/../Labs.Head.Uno.props +ApplyWinUISwap $PSScriptRoot/../Labs.Uno.props +ApplyWinUISwap $PSScriptRoot/../Labs.ProjectIdentifiers.props if ($allowGitChanges.IsPresent) { Write-Warning "Changes to the default Uno package settings in Labs can now be committed.`r`nRun this command again without -allowGitChanges to disable committing further changes."; From 280d271abd4cbd9f712103b67a1371029bddab30 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Tue, 13 Dec 2022 17:03:41 -0600 Subject: [PATCH 19/28] Fixed TargetFrameworks not respecting MultiTarget value --- common/MultiTarget/MultiTarget.props | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/MultiTarget/MultiTarget.props b/common/MultiTarget/MultiTarget.props index a1ee39363..7987a0942 100644 --- a/common/MultiTarget/MultiTarget.props +++ b/common/MultiTarget/MultiTarget.props @@ -1,11 +1,12 @@ + + + - uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; - $(TargetFrameworks);$(UwpTargetFramework) $(TargetFrameworks);$(WinAppSdkTargetFramework) - - - - From ff79ecaf2ccc4ab832f8c90993a25634dd7bc904 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Dec 2022 13:54:57 -0600 Subject: [PATCH 23/28] Added basic docs --- common/MultiTarget/ReadMe.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 common/MultiTarget/ReadMe.md diff --git a/common/MultiTarget/ReadMe.md b/common/MultiTarget/ReadMe.md new file mode 100644 index 000000000..e9800cb97 --- /dev/null +++ b/common/MultiTarget/ReadMe.md @@ -0,0 +1,36 @@ +# MultiTarget + +`` is a custom property that indicates which target a project is designed to be built for / run on. + +The supplied targets are used to create project references, generate solution files, enable/disable TargetFrameworks, and build nuget packages. + +## Basic usage + +Create a `MultiTarget.props` file in the same folder as your `.csproj` to change its MultiTarget. + +By default, all available targets are enabled: +```xml + + + uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; + + +``` + +A project with this `MultiTarget.props` would only target UWP, WASM and Android: + +```xml + + + uwp;wasm;android + + +``` + +## ProjectReference Generation + +The script `GenerateAllProjectReferences.ps1` will recursively scan the provided folders for `.csproj` files and generate a `.props` file with a MultiTarget-aware `` for each one. + +## NuGet Packages + +The `` property is used to define the `TargetFrameworks` supported by that project. Projects packed into a NuGet packages will reflect this. From 42d80b83500bd296ef1d422dc9498712a5bc3c07 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 14 Dec 2022 13:55:35 -0600 Subject: [PATCH 24/28] Remove "AllGeneratedProjectReferences.props" in favor of a wildcard import --- common/Labs.Head.props | 2 ++ ...lGeneratedProjectReferences.props.template | 13 ---------- .../GenerateAllProjectReferences.ps1 | 25 +------------------ .../CommunityToolkit.Labs.Droid.csproj | 2 +- .../CommunityToolkit.Labs.Skia.Gtk.csproj | 2 +- .../CommunityToolkit.Labs.Skia.WPF.csproj | 2 +- .../CommunityToolkit.Labs.Uwp.csproj | 2 +- .../CommunityToolkit.Labs.Wasm.csproj | 2 +- .../CommunityToolkit.Labs.WinAppSdk.csproj | 2 +- .../CommunityToolkit.Labs.iOS.csproj | 2 +- .../CommunityToolkit.Labs.macOS.csproj | 2 +- .../CommunityToolkit.Labs.Tests.Uwp.csproj | 2 +- ...mmunityToolkit.Labs.Tests.WinAppSdk.csproj | 2 +- 13 files changed, 13 insertions(+), 47 deletions(-) delete mode 100644 common/MultiTarget/AllGeneratedProjectReferences.props.template diff --git a/common/Labs.Head.props b/common/Labs.Head.props index 1b926edf9..3bf9273c5 100644 --- a/common/Labs.Head.props +++ b/common/Labs.Head.props @@ -29,6 +29,8 @@ true true true + + $(DefineConstants);LABS_ALL_SAMPLES diff --git a/common/MultiTarget/AllGeneratedProjectReferences.props.template b/common/MultiTarget/AllGeneratedProjectReferences.props.template deleted file mode 100644 index 4c1e066ce..000000000 --- a/common/MultiTarget/AllGeneratedProjectReferences.props.template +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - $(DefineConstants);LABS_ALL_SAMPLES - - [ProjectReferenceImports] - diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index 007f62ebc..6972a2e90 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -5,23 +5,10 @@ Param ( [Parameter(HelpMessage = "Filters projects that have paths which match the provided string.")] [string]$Exclude = "*template*", - [Parameter(HelpMessage = "The path to a props file that will be populated with project imports for all discovered projects.")] - [string]$outputPath = "$projectPropsOutputDir/AllGeneratedProjectReferences.props", - [Parameter(HelpMessage = "The directories to scan for projects. Supports wildcards.")] - [string[]]$projectDirectories = @("$PSScriptRoot/../../*/*/samples/*.Samples/*.Samples.csproj", "$PSScriptRoot/../../*/*/src/*.csproj"), - - [Parameter(HelpMessage = "The path to the template used to generate the props file.")] - [string]$templatePath = "$PSScriptRoot/AllGeneratedProjectReferences.props.template", - - [Parameter(HelpMessage = "The placeholder text to replace when inserting the project file name into the template.")] - [string]$projectReferencesDefinitionMarker = "[ProjectReferenceImports]" + [string[]]$projectDirectories = @("$PSScriptRoot/../../*/*/samples/*.Samples/*.Samples.csproj", "$PSScriptRoot/../../*/*/src/*.csproj") ) -# Load template -$templateContents = Get-Content -Path $templatePath; -Write-Output "Loaded template from $(Resolve-Path $templatePath)"; - # Create output folder if not exists New-Item -ItemType Directory -Force -Path $projectPropsOutputDir -ErrorAction SilentlyContinue | Out-Null; @@ -33,16 +20,6 @@ foreach ($path in $projectDirectories) { $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 $projectPath "$projectPropsOutputDir/$projectName.props"; - $projectReferenceDefinition = ""; - - $templateContents = $templateContents -replace [regex]::escape($projectReferencesDefinitionMarker), ($projectReferencesDefinitionMarker + " - " + $projectReferenceDefinition); } } -# Remove placeholder from template -$templateContents = $templateContents -replace [regex]::escape($projectReferencesDefinitionMarker), ""; - -# Save -Set-Content -Path $outputPath -Value $templateContents; -Write-Output "Project references generated at $(Resolve-Path $outputPath)"; diff --git a/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj b/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj index 20bc2da89..ad4b6c55b 100644 --- a/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj +++ b/platforms/CommunityToolkit.Labs.Droid/CommunityToolkit.Labs.Droid.csproj @@ -30,7 +30,7 @@ - + Debug diff --git a/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj b/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj index 92cc6a5f2..c600549e1 100644 --- a/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj +++ b/platforms/CommunityToolkit.Labs.Skia.Gtk/CommunityToolkit.Labs.Skia.Gtk.csproj @@ -27,7 +27,7 @@ - + WinExe diff --git a/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj b/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj index e5301e20d..b22502731 100644 --- a/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj +++ b/platforms/CommunityToolkit.Labs.Skia.WPF/CommunityToolkit.Labs.Skia.WPF.csproj @@ -28,7 +28,7 @@ - + diff --git a/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj b/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj index 93ffce3ce..1e5e0cce3 100644 --- a/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj +++ b/platforms/CommunityToolkit.Labs.Uwp/CommunityToolkit.Labs.Uwp.csproj @@ -26,7 +26,7 @@ - + CommunityToolkit.Labs.Uwp CommunityToolkit.Labs.Uwp diff --git a/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj b/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj index 39acdc379..57e00a533 100644 --- a/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj +++ b/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj @@ -28,7 +28,7 @@ - + diff --git a/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj b/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj index 0477a4584..f4eb9fe49 100644 --- a/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj +++ b/platforms/CommunityToolkit.Labs.WinAppSdk/CommunityToolkit.Labs.WinAppSdk.csproj @@ -26,7 +26,7 @@ - + CommunityToolkit.Labs.WinAppSdk diff --git a/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj b/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj index aff6084cd..8101f32a2 100644 --- a/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj +++ b/platforms/CommunityToolkit.Labs.iOS/CommunityToolkit.Labs.iOS.csproj @@ -30,7 +30,7 @@ - + Debug diff --git a/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj b/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj index f8c93345c..f18bd4145 100644 --- a/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj +++ b/platforms/CommunityToolkit.Labs.macOS/CommunityToolkit.Labs.macOS.csproj @@ -30,7 +30,7 @@ - + Debug diff --git a/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj b/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj index a0072be0c..a76a3e9c8 100644 --- a/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj +++ b/tests/CommunityToolkit.Labs.Tests.Uwp/CommunityToolkit.Labs.Tests.Uwp.csproj @@ -75,7 +75,7 @@ - + diff --git a/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj b/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj index 5bfe84f2f..90d54d1dc 100644 --- a/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj +++ b/tests/CommunityToolkit.Labs.Tests.WinAppSdk/CommunityToolkit.Labs.Tests.WinAppSdk.csproj @@ -56,5 +56,5 @@ - + From 14f52458574bc667be94312febca6614230cd01f Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Thu, 15 Dec 2022 18:27:50 -0600 Subject: [PATCH 25/28] Use MultiTarget values defined in Source project when not defined in Sample project --- .../GenerateAllProjectReferences.ps1 | 53 +++++++++++++------ ...eMultiTargetAwareProjectReferenceProps.ps1 | 11 ++-- common/MultiTarget/MultiTarget.props | 14 +++-- common/MultiTarget/ReadMe.md | 9 ++-- .../RivePlayer.Samples/MultiTarget.props | 9 ---- .../ProjectTemplate.Samples/MultiTarget.props | 9 ---- 6 files changed, 61 insertions(+), 44 deletions(-) delete mode 100644 labs/RivePlayer/samples/RivePlayer.Samples/MultiTarget.props delete mode 100644 template/lab/samples/ProjectTemplate.Samples/MultiTarget.props diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index 6972a2e90..12fafa1fd 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -1,25 +1,46 @@ Param ( - [Parameter(HelpMessage = "The directory where props files for discovered projects should be saved.")] - [string]$projectPropsOutputDir = "$PSScriptRoot/Generated", - - [Parameter(HelpMessage = "Filters projects that have paths which match the provided string.")] - [string]$Exclude = "*template*", - - [Parameter(HelpMessage = "The directories to scan for projects. Supports wildcards.")] - [string[]]$projectDirectories = @("$PSScriptRoot/../../*/*/samples/*.Samples/*.Samples.csproj", "$PSScriptRoot/../../*/*/src/*.csproj") + [Parameter(HelpMessage = "The directory where props files for discovered projects should be saved.")] + [string]$projectPropsOutputDir = "$PSScriptRoot/Generated" ) -# Create output folder if not exists +$preWorkingDir = $pwd; +Set-Location $PSScriptRoot; + +# Delete and recreate output folder. +Remove-Item -Path $projectPropsOutputDir -Recurse -Force -ErrorAction SilentlyContinue | Out-Null; New-Item -ItemType Directory -Force -Path $projectPropsOutputDir -ErrorAction SilentlyContinue | Out-Null; # Discover projects in provided paths -foreach ($path in $projectDirectories) { - foreach ($projectPath in Get-ChildItem -Recurse -Path $path -Exclude $Exclude) { - $relativePath = Resolve-Path -Relative -Path $projectPath; - $relativePath = $relativePath.TrimStart('.\'); - $projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath); - - & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 $projectPath "$projectPropsOutputDir/$projectName.props"; +foreach ($projectPath in Get-ChildItem -Directory -Depth 0 -Path "$PSScriptRoot/../../labs/") { + # Normalize project path + $projectName = $projectPath.Name; + + # Folder layout is expected to match the Community Toolkit. + # Uses the values from the source library project as the fallback for the sample project. + # This behavior also implemented in MultiTarget.props for TargetFramework evaluation. + $srcPath = Resolve-Path "$projectPath\src"; + $srcProjectPath = Get-ChildItem -File "$srcPath\*.csproj"; + + $samplePath = Resolve-Path "$projectPath\samples\$projectName.Samples"; + $sampleProjectPath = Get-ChildItem -File "$samplePath\*.csproj"; + + if ($srcProjectPath.Length -eq 0) { + Write-Error "Could not locate source csproj for $projectName"; + exit(-1); } + + if ($sampleProjectPath.Length -eq 0) { + Write-Error "Could not locate sample csproj for $projectName"; + exit(-1); + } + + # Generate s for sample project + # Use source project MultiTarget as first fallback. + & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $sampleProjectPath -outputPath "$projectPropsOutputDir/$($sampleProjectPath.BaseName).props" -multiTargetFallbackPropsPath @("$srcPath/MultiTarget.props", "$samplePath/MultiTarget.props", "$PSScriptRoot/Defaults.props"); + + # Generate s for src project + & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $srcProjectPath -outputPath "$projectPropsOutputDir/$($srcProjectPath.BaseName).props" -multiTargetFallbackPropsPath @("$srcPath/MultiTarget.props", "$PSScriptRoot/Defaults.props"); } + +Set-Location $preWorkingDir; \ No newline at end of file diff --git a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 index 418ea8646..5e4297463 100644 --- a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 +++ b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -9,7 +9,7 @@ Param ( [string]$templatePath = "$PSScriptRoot/MultiTargetAwareProjectReference.props.template", [Parameter(HelpMessage = "The path to the props file that contains the default MultiTarget values.")] - [string]$multiTargetDefaultPropsPath = "$PSScriptRoot/Defaults.props", + [string[]]$multiTargetFallbackPropsPath = @("$PSScriptRoot/Defaults.props"), [Parameter(HelpMessage = "The placeholder text to replace when inserting the project file name into the template.")] [string]$projectFileNamePlaceholder = "[ProjectFileName]", @@ -39,8 +39,13 @@ function LoadMultiTargetsFrom([string] $path) { # If file does not exist if ($false -eq (Test-Path -Path $path -PathType Leaf)) { - # Load defaults - $fileContents = Get-Content $multiTargetDefaultPropsPath -ErrorAction Stop; + # Load first available default + foreach ($fallbackPath in $multiTargetFallbackPropsPath) { + if (Test-Path $fallbackPath) { + $fileContents = Get-Content $fallbackPath -ErrorAction Stop; + break; + } + } } else { # Load requested file diff --git a/common/MultiTarget/MultiTarget.props b/common/MultiTarget/MultiTarget.props index 7987a0942..37ff1b8b4 100644 --- a/common/MultiTarget/MultiTarget.props +++ b/common/MultiTarget/MultiTarget.props @@ -1,6 +1,14 @@ - - + + true + + + + + + + + - uwp;wasdk;wasm; - - \ No newline at end of file diff --git a/template/lab/samples/ProjectTemplate.Samples/MultiTarget.props b/template/lab/samples/ProjectTemplate.Samples/MultiTarget.props deleted file mode 100644 index b11c19426..000000000 --- a/template/lab/samples/ProjectTemplate.Samples/MultiTarget.props +++ /dev/null @@ -1,9 +0,0 @@ - - - - uwp;wasdk;wpf;wasm;linuxgtk;macos;ios;android; - - \ No newline at end of file From 63bf5d012e657f1c19dc74841199ab2b820bd323 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 16 Dec 2022 11:26:06 -0600 Subject: [PATCH 26/28] Updated docs --- common/MultiTarget/ReadMe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/MultiTarget/ReadMe.md b/common/MultiTarget/ReadMe.md index e5c6fd741..c4f7eaf64 100644 --- a/common/MultiTarget/ReadMe.md +++ b/common/MultiTarget/ReadMe.md @@ -30,7 +30,7 @@ For example, to only target UWP, WASM and Android: ## ProjectReference Generation -The script `GenerateAllProjectReferences.ps1` will scan for experiments and generate `.props` files for each project. +The script `GenerateAllProjectReferences.ps1` will scan for toolkit components and generate `.props` files for each. ## NuGet Packages From 6c5a0a379a8b193a1bc5015ff3f17a597ebc9476 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 16 Dec 2022 12:06:19 -0600 Subject: [PATCH 27/28] Fixed project generation in PowerShell 5.1 --- common/MultiTarget/GenerateAllProjectReferences.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/MultiTarget/GenerateAllProjectReferences.ps1 b/common/MultiTarget/GenerateAllProjectReferences.ps1 index 12fafa1fd..5bb8fad65 100644 --- a/common/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/common/MultiTarget/GenerateAllProjectReferences.ps1 @@ -18,10 +18,10 @@ foreach ($projectPath in Get-ChildItem -Directory -Depth 0 -Path "$PSScriptRoot/ # Folder layout is expected to match the Community Toolkit. # Uses the values from the source library project as the fallback for the sample project. # This behavior also implemented in MultiTarget.props for TargetFramework evaluation. - $srcPath = Resolve-Path "$projectPath\src"; + $srcPath = Resolve-Path "$($projectPath.FullName)\src"; $srcProjectPath = Get-ChildItem -File "$srcPath\*.csproj"; - $samplePath = Resolve-Path "$projectPath\samples\$projectName.Samples"; + $samplePath = Resolve-Path "$($projectPath.FullName)\samples\$projectName.Samples"; $sampleProjectPath = Get-ChildItem -File "$samplePath\*.csproj"; if ($srcProjectPath.Length -eq 0) { From a353aed7fe41659bee39d0fa93edf555e7885bf6 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Tue, 20 Dec 2022 14:05:24 -0600 Subject: [PATCH 28/28] Add comment to generated files indicating original MultiTarget value --- .../GenerateMultiTargetAwareProjectReferenceProps.ps1 | 4 +++- .../MultiTargetAwareProjectReference.props.template | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 index 5e4297463..a50ccdacb 100644 --- a/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 +++ b/common/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -65,8 +65,10 @@ function LoadMultiTargetsFrom([string] $path) { # Load multitarget preferences for project $multiTargets = LoadMultiTargetsFrom("$([System.IO.Path]::GetDirectoryName($projectPath))\MultiTarget.props"); -$multiTargets = $multiTargets.Split(';'); +$templateContents = $templateContents -replace [regex]::escape("[IntendedTargets]"), $multiTargets; + +$multiTargets = $multiTargets.Split(';'); Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($multiTargets -Join ', ')" $templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$($multiTargets.Contains("wasm").ToString().ToLower())'"; diff --git a/common/MultiTarget/MultiTargetAwareProjectReference.props.template b/common/MultiTarget/MultiTargetAwareProjectReference.props.template index cbcf09aa9..7fea92b4b 100644 --- a/common/MultiTarget/MultiTargetAwareProjectReference.props.template +++ b/common/MultiTarget/MultiTargetAwareProjectReference.props.template @@ -6,6 +6,7 @@ +