Skip to content

Commit

Permalink
#508: Improved plugin handling for netstandard2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Apr 26, 2022
1 parent 3655bd3 commit c7a5c6f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Deployment/nuget/ReportGenerator.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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.5.0

* Fix: #508: Improved plugin handling for netstandard2.0

5.1.4.0

* Fix: #408: Improved support for generic classes for 'dotnet-coverage'
Expand Down
25 changes: 19 additions & 6 deletions src/ReportGenerator.Core/Plugin/ReflectionPluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public IReadOnlyCollection<T> LoadInstancesOfType<T>()
}
}

if (this.plugins.Count == 0)
if (this.plugins.Count == 0 || this.assemblyLoader == null)
{
return result;
}
Expand Down Expand Up @@ -114,11 +114,24 @@ private IAssemblyLoader CreateAssemblyLoader()
var directory = new FileInfo(typeof(ReflectionPluginLoader).Assembly.Location).Directory.FullName;
string path = Path.Combine(directory, "ReportGenerator.DotnetCorePluginLoader.dll");

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));
if (!File.Exists(path))
{
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;
}
}

return new DefaultAssemblyLoader();
Expand Down
9 changes: 9 additions & 0 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.

3 changes: 3 additions & 0 deletions src/ReportGenerator.Core/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
<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

0 comments on commit c7a5c6f

Please sign in to comment.