From 1b6a0a61ba5af0112b061bb8de883083094e7684 Mon Sep 17 00:00:00 2001 From: Arlo Date: Fri, 29 Sep 2023 14:42:28 -0500 Subject: [PATCH] Implemented new AddMultiTargetCompatibleSampleDocs target (#141) * Added AddMultiTargetCompatibleSampleDocs target. Fixes #5. * Fixed a lowercase T * Fixed target execution order * Use RoslynCodeTaskFactory * Fix typo * Fixed MultiTarget Identifiers --- ProjectHeads/App.Head.props | 9 +- ...AddMultiTargetCompatibleSampleDocs.targets | 41 ++++++ ProjectHeads/Tasks/CheckMultiTarget.props | 131 ++++++++++++++++++ 3 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 ProjectHeads/Targets/AddMultiTargetCompatibleSampleDocs.targets create mode 100644 ProjectHeads/Tasks/CheckMultiTarget.props diff --git a/ProjectHeads/App.Head.props b/ProjectHeads/App.Head.props index 5e36c67c..5c77f6b3 100644 --- a/ProjectHeads/App.Head.props +++ b/ProjectHeads/App.Head.props @@ -3,6 +3,9 @@ + + + @@ -64,7 +67,7 @@ - + @@ -76,6 +79,8 @@ + + @@ -92,8 +97,6 @@ SourceAssets/%(RecursiveDir)%(FileName)%(Extension).dat - - diff --git a/ProjectHeads/Targets/AddMultiTargetCompatibleSampleDocs.targets b/ProjectHeads/Targets/AddMultiTargetCompatibleSampleDocs.targets new file mode 100644 index 00000000..02d0ea88 --- /dev/null +++ b/ProjectHeads/Targets/AddMultiTargetCompatibleSampleDocs.targets @@ -0,0 +1,41 @@ + + + + + + + + uwp + wasm + wasdk + macos + ios + android + netstandard + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ProjectHeads/Tasks/CheckMultiTarget.props b/ProjectHeads/Tasks/CheckMultiTarget.props new file mode 100644 index 00000000..812b68fe --- /dev/null +++ b/ProjectHeads/Tasks/CheckMultiTarget.props @@ -0,0 +1,131 @@ + + + + + + + + + + + + + GetMultiTargetPropsPath = (parent, subDir) => System.IO.Path.Combine(parent, subDir, "MultiTarget.props"); + Func ReadMultiTargetPropsOrDefault = path => System.IO.File.Exists(path) ? System.IO.File.ReadAllText(path) : string.Empty; + Func ExtractMultiTargetIdentifier = content => { + System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(content, @"([^<]*)", System.Text.RegularExpressions.RegexOptions.Singleline); + return match.Success ? match.Groups[1].Value : string.Empty; + }; + + multiTargetPropsPath = GetMultiTargetPropsPath(parentComponent, "sample"); + multiTargetPropsContent = ReadMultiTargetPropsOrDefault(multiTargetPropsPath); + multiTargetIdentifier = ExtractMultiTargetIdentifier(multiTargetPropsContent); + + if (string.IsNullOrEmpty(multiTargetIdentifier)) + { + multiTargetPropsPath = GetMultiTargetPropsPath(parentComponent, "src"); + multiTargetPropsContent = ReadMultiTargetPropsOrDefault(multiTargetPropsPath); + multiTargetIdentifier = ExtractMultiTargetIdentifier(multiTargetPropsContent); + } + + if (string.IsNullOrWhiteSpace(multiTargetIdentifier)) + { + multiTargetPropsPath = System.IO.Path.Combine(RepositoryDirectory, "tooling", "MultiTarget", "Defaults.props"); + multiTargetPropsContent = ReadMultiTargetPropsOrDefault(multiTargetPropsPath); + multiTargetIdentifier = ExtractMultiTargetIdentifier(multiTargetPropsContent); + } + + IsSupported = multiTargetIdentifier.Split(';').Contains(MultiTargetIdentifier); + FilePath.SetMetadata("IsSupported", IsSupported.ToString()); + ]]> + + + + + +