From c654af64cf2381ddd899f19270571e0dcc62a447 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Thu, 24 Jun 2021 08:38:38 -0700 Subject: [PATCH 1/2] Recognize files in ref-pack under "analyzers" as analyzers and write them to the frameworkList --- .../src/CreateFrameworkListFile.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Microsoft.DotNet.SharedFramework.Sdk/src/CreateFrameworkListFile.cs b/src/Microsoft.DotNet.SharedFramework.Sdk/src/CreateFrameworkListFile.cs index 984fee0faa3..be0e8b2b6ec 100644 --- a/src/Microsoft.DotNet.SharedFramework.Sdk/src/CreateFrameworkListFile.cs +++ b/src/Microsoft.DotNet.SharedFramework.Sdk/src/CreateFrameworkListFile.cs @@ -131,11 +131,41 @@ public override bool Execute() } } + string analyzerLanguage = null; + + if (path.StartsWith("analyzers/")) + { + type = "Analyzer"; + + if (path.EndsWith(".resources.dll")) + { + // omit analyzer resources + continue; + } + + var pathParts = path.Split('/'); + + if (pathParts.Length < 3 || !pathParts[1].Equals("dotnet", StringComparison.Ordinal) || pathParts.Length > 4) + { + Log.LogError($"Unexpected analyzer path format {path}. Expected 'analyzers/dotnet(/language)/analyzer.dll"); + } + + if (pathParts.Length > 3) + { + analyzerLanguage = pathParts[2]; + } + } + var element = new XElement( "File", new XAttribute("Type", type), new XAttribute("Path", path)); + if (analyzerLanguage != null) + { + element.Add(new XAttribute("Language", analyzerLanguage)); + } + if (f.IsResourceFile) { element.Add( From 88e0108f0dfa12a13c770e884d41ead96fd148c3 Mon Sep 17 00:00:00 2001 From: Eric StJohn Date: Mon, 28 Jun 2021 23:15:19 -0700 Subject: [PATCH 2/2] Fixes to support analyzer packaging Platform manifest creation uses a dictionary to map template items to files in the package, but didn't account for duplicate file names (as is the case with .resources.dll). Handle this by taking the first file of a particular name. Include `analyzer/` prefixed files in framework list. Allow for analyzers to be excluded from closure and type validation with ExcludeFromValidation metadata. This metadata is necessary because analyzers will be missing dependencies provided by the compiler, and their resource.dll will have duplicate files, both which would result in errors. --- .../src/GeneratePlatformManifestEntriesFromTemplate.cs | 2 +- .../targets/sharedfx.targets | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.SharedFramework.Sdk/src/GeneratePlatformManifestEntriesFromTemplate.cs b/src/Microsoft.DotNet.SharedFramework.Sdk/src/GeneratePlatformManifestEntriesFromTemplate.cs index fc798d6e028..e8346c2b79a 100644 --- a/src/Microsoft.DotNet.SharedFramework.Sdk/src/GeneratePlatformManifestEntriesFromTemplate.cs +++ b/src/Microsoft.DotNet.SharedFramework.Sdk/src/GeneratePlatformManifestEntriesFromTemplate.cs @@ -30,7 +30,7 @@ public class GeneratePlatformManifestEntriesFromTemplate : BuildTask public override bool Execute() { List entries = new List(); - var files = Files.ToDictionary(file => Path.GetFileName(file.ItemSpec)); + var files = Files.ToLookup(file => Path.GetFileName(file.ItemSpec)).ToDictionary(l => l.Key, l=> l.First()); foreach (var entryTemplate in PlatformManifestEntryTemplates) { if (files.TryGetValue(entryTemplate.ItemSpec, out ITaskItem existingFile)) diff --git a/src/Microsoft.DotNet.SharedFramework.Sdk/targets/sharedfx.targets b/src/Microsoft.DotNet.SharedFramework.Sdk/targets/sharedfx.targets index 395f2e3cbb0..df74bf08695 100644 --- a/src/Microsoft.DotNet.SharedFramework.Sdk/targets/sharedfx.targets +++ b/src/Microsoft.DotNet.SharedFramework.Sdk/targets/sharedfx.targets @@ -385,7 +385,7 @@ <_FrameworkListRootAttribute Include="TargetFrameworkVersion" Value="$(TargetFrameworkVersion.TrimStart('vV'))" /> <_FrameworkListRootAttribute Include="FrameworkName" Value="$(SharedFrameworkName)" /> <_FrameworkListRootAttribute Include="Name" Value="$(SharedFrameworkFriendlyName)" /> - <_FrameworkListTargetFilePrefix Include="ref/;runtimes/" /> + <_FrameworkListTargetFilePrefix Include="ref/;runtimes/;analyzers/" /> <_FrameworkListTargetFilePrefix Condition="'$(PlatformPackageType)' == 'RuntimePack'" Include="PgoData" /> @@ -448,7 +448,7 @@ <_closureFiles Include="@(FilesToPackage)" - Condition="('%(Extension)' == '.dll' or '%(Extension)' == '$(LibraryFileExtension)') and '%(FilesToPackage.Culture)' == ''" /> + Condition="('%(Extension)' == '.dll' or '%(Extension)' == '$(LibraryFileExtension)') and '%(FilesToPackage.Culture)' == '' and '%(FilesToPackage.ExcludeFromValidation)' != 'true'" /> <_closureFileNames Include="@(_closureFiles->'%(FileName)')" Original="%(Identity)" /> <_closureFileNamesFiltered Include="@(_closureFileNames)" Exclude="@(ExcludeFromClosure)"/> @@ -478,7 +478,7 @@ <_dupTypeFiles Include="@(FilesToPackage)" - Condition="('%(Extension)' == '.dll' or '%(Extension)' == '$(LibraryFileExtension)') and '%(FilesToPackage.Culture)' == ''" /> + Condition="('%(Extension)' == '.dll' or '%(Extension)' == '$(LibraryFileExtension)') and '%(FilesToPackage.Culture)' == '' and '%(FilesToPackage.ExcludeFromValidation)' != 'true'" /> <_dupTypeFileName Include="@(_dupTypeFiles->'%(FileName)')" Original="%(Identity)" /> <_dupTypeFileNamesFiltered Include="@(_dupTypeFileName)" Exclude="@(ExcludeFromDuplicateTypes)"/>