From 97ed499d8a4fe3bbc92a1939f1bfc1b2e2513faf Mon Sep 17 00:00:00 2001
From: ThomasGoulet73 <51839772+ThomasGoulet73@users.noreply.github.com>
Date: Tue, 14 Jun 2022 01:26:15 -0400
Subject: [PATCH] Fix build when using source generators (#6534)
Fixes dotnet/wpf#6522
---
.../Microsoft.WinFX.targets | 3 ++-
.../Windows/GenerateTemporaryTargetAssembly.cs | 17 +++++++++++++++--
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFX.targets b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFX.targets
index 2b51517e7c3..aef40014f29 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFX.targets
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFX.targets
@@ -464,6 +464,7 @@
MSBuildBinPath="$(MSBuildBinPath)"
ReferencePathTypeName="ReferencePath"
CompileTypeName="Compile"
+ AnalyzerTypeName="Analyzer"
GeneratedCodeFiles="@(_GeneratedCodeFiles)"
ReferencePath="@(ReferencePath)"
BaseIntermediateOutputPath="$(BaseIntermediateOutputPath)"
@@ -472,7 +473,7 @@
CompileTargetName="$(_CompileTargetNameForLocalType)"
GenerateTemporaryTargetAssemblyDebuggingInformation="$(GenerateTemporaryTargetAssemblyDebuggingInformation)"
IncludePackageReferencesDuringMarkupCompilation="$(IncludePackageReferencesDuringMarkupCompilation)"
- Analyzers="$(Analyzers)"
+ Analyzers="@(Analyzer)"
TemporaryTargetAssemblyProjectName="$(_TemporaryTargetAssemblyProjectName)"
MSBuildProjectExtensionsPath="$(MSBuildProjectExtensionsPath)"
>
diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
index 80a436dce22..da314af0bfb 100644
--- a/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
+++ b/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs
@@ -262,6 +262,9 @@ private bool ExecuteGenerateTemporaryTargetAssemblyWithPackageReferenceSupport()
// Add GeneratedCodeFiles to Compile item list.
AddNewItems(xmlProjectDoc, CompileTypeName, GeneratedCodeFiles);
+ // Add Analyzers to Analyzer item list.
+ AddNewItems(xmlProjectDoc, AnalyzerTypeName, Analyzers);
+
// Replace implicit SDK imports with explicit SDK imports
ReplaceImplicitImports(xmlProjectDoc);
@@ -273,7 +276,6 @@ private bool ExecuteGenerateTemporaryTargetAssemblyWithPackageReferenceSupport()
( nameof(BaseIntermediateOutputPath), BaseIntermediateOutputPath ),
( nameof(MSBuildProjectExtensionsPath), MSBuildProjectExtensionsPath ),
( "_TargetAssemblyProjectName", Path.GetFileNameWithoutExtension(CurrentProject) ),
- ( nameof(Analyzers), Analyzers )
};
AddNewProperties(xmlProjectDoc, properties);
@@ -480,9 +482,20 @@ public bool GenerateTemporaryTargetAssemblyDebuggingInformation
/// Required for Source Generator support. May be null.
///
///
- public string Analyzers
+ public ITaskItem[] Analyzers
{ get; set; }
+ ///
+ /// AnalyzerTypeName
+ /// The appropriate item name which can be accepted by managed compiler task.
+ /// It is "Analyzer" for now.
+ ///
+ /// Adding this property is to make the type name configurable, if it is changed,
+ /// No code is required to change in this task, but set a new type name in project file.
+ ///
+ [Required]
+ public string AnalyzerTypeName { get; set; }
+
///
/// BaseIntermediateOutputPath
///