From d0028f92fa3c6e856baa60f347c3e57a762ee75c Mon Sep 17 00:00:00 2001 From: danielpalme Date: Sun, 1 May 2022 19:47:57 +0200 Subject: [PATCH] #514: Improved plugin handling for netstandard2.0 --- .../nuget/ReportGenerator.Core.nuspec | 1 - src/Readme.txt | 4 +++ .../Plugin/ReflectionPluginLoader.cs | 36 +++++++++++-------- .../Properties/Resources.Designer.cs | 18 +++++----- .../Properties/Resources.resx | 6 ++-- 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/Deployment/nuget/ReportGenerator.Core.nuspec b/src/Deployment/nuget/ReportGenerator.Core.nuspec index 845b0961..e43294e4 100644 --- a/src/Deployment/nuget/ReportGenerator.Core.nuspec +++ b/src/Deployment/nuget/ReportGenerator.Core.nuspec @@ -30,7 +30,6 @@ https://github.com/danielpalme/ReportGenerator/wiki/Custom-history-storage - diff --git a/src/Readme.txt b/src/Readme.txt index d1aae0bc..275bbcfa 100644 --- a/src/Readme.txt +++ b/src/Readme.txt @@ -67,6 +67,10 @@ For further details take a look at LICENSE.txt. CHANGELOG +5.1.6.0 + + * Fix: #514: Improved plugin handling for netstandard2.0 + 5.1.5.0 * Fix: #508: Improved plugin handling for netstandard2.0 diff --git a/src/ReportGenerator.Core/Plugin/ReflectionPluginLoader.cs b/src/ReportGenerator.Core/Plugin/ReflectionPluginLoader.cs index dfd7eac0..06eab39e 100644 --- a/src/ReportGenerator.Core/Plugin/ReflectionPluginLoader.cs +++ b/src/ReportGenerator.Core/Plugin/ReflectionPluginLoader.cs @@ -19,6 +19,11 @@ internal class ReflectionPluginLoader : IPluginLoader /// private static readonly ILogger Logger = LoggerFactory.GetLogger(typeof(ReflectionPluginLoader)); + /// + /// Indicates whether an exception occured to prevent logging same exception several times. + /// + private static bool pluginsNotSupportedMessageShown; + /// /// The plugins. /// @@ -63,8 +68,19 @@ public IReadOnlyCollection LoadInstancesOfType() } } - if (this.plugins.Count == 0 || this.assemblyLoader == null) + if (this.plugins.Count == 0) + { + return result; + } + + if (this.assemblyLoader == null) { + if (!pluginsNotSupportedMessageShown) + { + Logger.Error(Resources.PluginsNotSupported); + pluginsNotSupportedMessageShown = true; + } + return result; } @@ -119,19 +135,11 @@ private IAssemblyLoader CreateAssemblyLoader() return null; } - try - { - var dotnetCorePluginLoaderAssembly = Assembly.LoadFrom(path); - var assemblyLoaderType = dotnetCorePluginLoaderAssembly.GetExportedTypes() - .Where(t => t.FullName == "ReportGenerator.DotnetCorePluginLoader.DotNetCoreAssemblyLoader" && t.IsClass && !t.IsAbstract) - .Single(); - return new ReflectionWrapperAssemblyLoader(Activator.CreateInstance(assemblyLoaderType)); - } - catch (Exception ex) - { - Logger.Error(string.Format(Resources.FailedToLoadPluginLoader, ex.Message)); - return null; - } + var dotnetCorePluginLoaderAssembly = Assembly.LoadFrom(path); + var assemblyLoaderType = dotnetCorePluginLoaderAssembly.GetExportedTypes() + .Where(t => t.FullName == "ReportGenerator.DotnetCorePluginLoader.DotNetCoreAssemblyLoader" && t.IsClass && !t.IsAbstract) + .Single(); + return new ReflectionWrapperAssemblyLoader(Activator.CreateInstance(assemblyLoaderType)); } return new DefaultAssemblyLoader(); diff --git a/src/ReportGenerator.Core/Properties/Resources.Designer.cs b/src/ReportGenerator.Core/Properties/Resources.Designer.cs index 068d625b..1fde1164 100644 --- a/src/ReportGenerator.Core/Properties/Resources.Designer.cs +++ b/src/ReportGenerator.Core/Properties/Resources.Designer.cs @@ -330,15 +330,6 @@ internal class Resources { } } - /// - /// Looks up a localized string similar to Failed to load plugin loader (Error: '{0}').. - /// - internal static string FailedToLoadPluginLoader { - get { - return ResourceManager.GetString("FailedToLoadPluginLoader", resourceCulture); - } - } - /// /// Looks up a localized string similar to Failed to load plugins from '{0}'. Make sure plugin has a strong name.. /// @@ -547,6 +538,15 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to Plugins are not supported in a .NET Standard environment. . + /// + internal static string PluginsNotSupported { + get { + return ResourceManager.GetString("PluginsNotSupported", resourceCulture); + } + } + /// /// Looks up a localized string similar to Preprocessing report. /// diff --git a/src/ReportGenerator.Core/Properties/Resources.resx b/src/ReportGenerator.Core/Properties/Resources.resx index 08a79f88..3d7f5582 100644 --- a/src/ReportGenerator.Core/Properties/Resources.resx +++ b/src/ReportGenerator.Core/Properties/Resources.resx @@ -207,9 +207,6 @@ Failed to instantiate plugin class '{0}'. - - Failed to load plugin loader (Error: '{0}'). - Failed to load plugins from '{0}'. Make sure plugin has a strong name. @@ -280,6 +277,9 @@ Parsing of {0} files completed + + Plugins are not supported in a .NET Standard environment. + Preprocessing report