Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GenerateAllSolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ foreach ($componentName in $Components) {

[void]$projects.Add(".\components\$($componentPath.BaseName)\src\*.csproj")
[void]$projects.Add(".\components\$($componentPath.BaseName)\samples\*.Samples.csproj")
[void]$projects.Add(".\components\$($componentPath.BaseName)\tests\*.Tests\*.shproj")
[void]$projects.Add(".\components\$($componentPath.BaseName)\tests\*.shproj")
} else {
Write-Warning "Component $($componentPath.BaseName) doesn't MultiTarget any of $MultiTargets and won't be added to the solution.";
}
Expand Down
2 changes: 1 addition & 1 deletion MultiTarget/EnabledMultiTargets.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<!--Indicates which MultiTargets are enabled via UseTargetFrameworks script. -->
<!-- Do not commit changes made to default values by tooling. -->
<PropertyGroup>
<EnabledMultiTargets>wasm;uwp;netstandard;</EnabledMultiTargets>
<EnabledMultiTargets>wasm;wasdk;</EnabledMultiTargets>
</PropertyGroup>
</Project>
16 changes: 11 additions & 5 deletions MultiTarget/GenerateAllProjectReferences.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ foreach ($componentName in $Components) {
continue;
}

# Find all components source csproj (when wildcard), or find specific component csproj by name.
# Find all components source/sample/test projects (when wildcard), or find specific component projects by component name.
foreach ($componentPath in Get-Item "$PSScriptRoot/../../components/$componentName/") {
$componentName = $componentPath.BaseName;
Write-Output "Generating project references for component $componentName at $componentPath";

# Find source and sample csproj files
# Find source, sample and test project files
$componentSourceCsproj = Get-ChildItem $componentPath/src/*.csproj -ErrorAction SilentlyContinue;
$componentSampleCsproj = Get-ChildItem $componentPath/samples/*.csproj -ErrorAction SilentlyContinue;
$componentTestProj = Get-ChildItem $componentPath/tests/*.projitems -ErrorAction SilentlyContinue;

# Generate <ProjectReference>s for sample project
# Use source project MultiTarget as first fallback.
if ($null -ne $componentSampleCsproj -and (Test-Path $componentSampleCsproj)) {
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSampleCsproj -outputPath "$projectPropsOutputDir/$($componentSampleCsproj.BaseName).props" -MultiTargets $MultiTargets
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSampleCsproj -outputPath "$projectPropsOutputDir/$($componentName).Samples.props" -MultiTargets $MultiTargets
}

# Generate <ProjectReference>s for src project
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSourceCsproj -outputPath "$projectPropsOutputDir/$($componentSourceCsproj.BaseName).props" -MultiTargets $MultiTargets
if ($null -ne $componentTestProj -and (Test-Path $componentTestProj)) {
# Generate references for test project
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentTestProj -outputPath "$projectPropsOutputDir/$($componentName).Tests.props" -MultiTargets $MultiTargets
}

# Generate references for src project
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSourceCsproj -outputPath "$projectPropsOutputDir/$($componentName).Source.props" -MultiTargets $MultiTargets
}
}

Expand Down
24 changes: 17 additions & 7 deletions MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Param (
[Parameter(HelpMessage = "The full path of the csproj to generated references to.", Mandatory = $true)]
[Parameter(HelpMessage = "The full path of the csproj or projitems to generate a reference to.", Mandatory = $true)]
[string]$projectPath,

[Parameter(HelpMessage = "A path to a .props file where generated content should be saved to.", Mandatory = $true)]
[Parameter(HelpMessage = "A path to where the generated .props file containing the reference 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",
[string]$templatePath,

[Parameter(HelpMessage = "The placeholder text to replace when inserting the project file name into the template.")]
[string]$projectFileNamePlaceholder = "[ProjectFileName]",
Expand All @@ -20,6 +20,16 @@ Param (
[string[]] $MultiTargets = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard")
)

if ($projectPath.EndsWith(".projitems")) {
$templatePath = "$PSScriptRoot/MultiTargetAwareSharedProjectImport.props.template"
} elseif ($projectPath.EndsWith(".csproj")) {
$templatePath = "$PSScriptRoot/MultiTargetAwareProjectReference.props.template";

} else {
Write-Error "The specified project path is not a valid csproj or projitems file: $projectPath";
exit(-1);
}

$templateContents = Get-Content -Path $templatePath;

$preWorkingDir = $pwd;
Expand All @@ -29,9 +39,9 @@ $relativeProjectPath = Resolve-Path -Relative -Path $projectPath

Set-Location $preWorkingDir;

# Insert csproj file name.
$csprojFileName = [System.IO.Path]::GetFileName($projectPath);
$templateContents = $templateContents -replace [regex]::escape($projectFileNamePlaceholder), $csprojFileName;
# Insert project file name.
$projectFileName = [System.IO.Path]::GetFileName($projectPath);
$templateContents = $templateContents -replace [regex]::escape($projectFileNamePlaceholder), $projectFileName;

# Insert component directory
$componentDirectoryRelativeToRoot = [System.IO.Path]::GetDirectoryName($relativeProjectPath).TrimStart('.').TrimStart('\');
Expand Down Expand Up @@ -67,7 +77,7 @@ function ShouldMultiTargetMsBuildValue([string] $target) {
$targeted = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard").Where({ ShouldMultiTarget $_ })

if ($targeted.Count -gt 0) {
Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($targeted -Join ', ')"
Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($projectFileName)): $($targeted -Join ', ')"
}

$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$(ShouldMultiTargetMsBuildValue "wasm")'";
Expand Down
19 changes: 19 additions & 0 deletions MultiTarget/MultiTargetAwareSharedProjectImport.props.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
This file was generated by a tool.
Adds a ProjectReference only if the referenced project indicates it can target the referencing project.
-->
<Project>
<Import Condition="($(IsWasm) == 'true' AND 'false' == 'true') OR
($(IsUwp) == 'true' AND 'false' == 'true') OR
($(IsWinAppSdk) == 'true' AND 'true' == 'true') OR
($(IsWpf) == 'true' AND 'false' == 'true') OR
($(IsGtk) == 'true' AND 'false' == 'true') OR
($(IsMacOS) == 'true' AND 'false' == 'true') OR
($(IsiOS) == 'true' AND 'false' == 'true') OR
($(IsDroid) == 'true' AND 'false' == 'true') OR
($(IsNetstandard) == 'true' AND 'false' == 'true')"
Project="$(RepositoryDirectory)[ProjectRoot]\[ProjectFileName]"
Label="Shared" />
</Project>


3 changes: 0 additions & 3 deletions ProjectHeads/AllComponents/Tests.Head.AllComponents.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<!-- Needed Unit Testing helper base classes -->
<Import Project="$(ToolingDirectory)\CommunityToolkit.Tests.Shared\CommunityToolkit.Tests.Shared.projitems" Label="Unit Testing Helpers" />

<!-- Visual Studio likes to delete the following line - but it's needed to find the tests -->
<Import Project="$(RepositoryDirectory)components\**\*.Tests.projitems" Label="Shared" />

<!-- Include all base code to be tested -->
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<Import Project="$(ToolingDirectory)\MultiTarget\EnabledTargetFrameworks.props" />
<Import Project="$(ToolingDirectory)\ProjectHeads\App.Head.Uwp.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\DefinedConstants.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.Samples.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.Source.props" />

<PropertyGroup>
<RootNamespace>CommunityToolkit.App.Uwp</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<Import Project="$(ToolingDirectory)\MultiTarget\EnabledTargetFrameworks.props" />

<Import Project="$(ToolingDirectory)\MultiTarget\DefinedConstants.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.Samples.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.Source.props" />
<Import Project="$(ToolingDirectory)\ProjectHeads\App.Head.WinAppSdk.props" />

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

<Import Project="$(ToolingDirectory)\MultiTarget\WinUI.TargetVersion.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\DefinedConstants.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.Samples.props" />
<Import Project="$(ToolingDirectory)\MultiTarget\Generated\*.Source.props" />
<Import Project="$(ToolingDirectory)\ProjectHeads\App.Head.Wasm.props" />

<ItemGroup>
Expand Down
Loading