Skip to content

Commit

Permalink
#514: Improved plugin handling for netstandard2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed May 1, 2022
1 parent e59bfde commit d0028f9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/Deployment/nuget/ReportGenerator.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ https://github.com/danielpalme/ReportGenerator/wiki/Custom-history-storage</desc
<dependency id="Microsoft.Extensions.Configuration.Json" version="5.0.0" />
<dependency id="SixLabors.ImageSharp.Drawing" version="1.0.0-beta14" />
<dependency id="DotNetConfig" version="1.0.6" />
<dependency id="McMaster.NETCore.Plugins" version="1.4.0" />
</group>

<group targetFramework="netcoreapp">
Expand Down
4 changes: 4 additions & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions src/ReportGenerator.Core/Plugin/ReflectionPluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ internal class ReflectionPluginLoader : IPluginLoader
/// </summary>
private static readonly ILogger Logger = LoggerFactory.GetLogger(typeof(ReflectionPluginLoader));

/// <summary>
/// Indicates whether an exception occured to prevent logging same exception several times.
/// </summary>
private static bool pluginsNotSupportedMessageShown;

/// <summary>
/// The plugins.
/// </summary>
Expand Down Expand Up @@ -63,8 +68,19 @@ public IReadOnlyCollection<T> LoadInstancesOfType<T>()
}
}

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;
}

Expand Down Expand Up @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions src/ReportGenerator.Core/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/ReportGenerator.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@
<data name="FailedToInstantiatePlugin" xml:space="preserve">
<value>Failed to instantiate plugin class '{0}'.</value>
</data>
<data name="FailedToLoadPluginLoader" xml:space="preserve">
<value>Failed to load plugin loader (Error: '{0}').</value>
</data>
<data name="FailedToLoadPlugins" xml:space="preserve">
<value>Failed to load plugins from '{0}'. Make sure plugin has a strong name.</value>
</data>
Expand Down Expand Up @@ -280,6 +277,9 @@
<data name="ParsingCompleted" xml:space="preserve">
<value>Parsing of {0} files completed</value>
</data>
<data name="PluginsNotSupported" xml:space="preserve">
<value>Plugins are not supported in a .NET Standard environment. </value>
</data>
<data name="PreprocessingReport" xml:space="preserve">
<value>Preprocessing report</value>
</data>
Expand Down

0 comments on commit d0028f9

Please sign in to comment.