diff --git a/demo/BlazorLazyLoading.Components.props b/demo/BlazorLazyLoading.Components.props
new file mode 100644
index 0000000..22417eb
--- /dev/null
+++ b/demo/BlazorLazyLoading.Components.props
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/BlazorLazyLoading.Module.props b/demo/BlazorLazyLoading.Module.props
new file mode 100644
index 0000000..578e013
--- /dev/null
+++ b/demo/BlazorLazyLoading.Module.props
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/BlazorLazyLoading.Server.props b/demo/BlazorLazyLoading.Server.props
new file mode 100644
index 0000000..1977d8b
--- /dev/null
+++ b/demo/BlazorLazyLoading.Server.props
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/BlazorLazyLoading.Wasm.props b/demo/BlazorLazyLoading.Wasm.props
new file mode 100644
index 0000000..9937f1a
--- /dev/null
+++ b/demo/BlazorLazyLoading.Wasm.props
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/Demo.sln b/demo/Demo.sln
index 97f9b9e..e947539 100644
--- a/demo/Demo.sln
+++ b/demo/Demo.sln
@@ -37,6 +37,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LazyAreas", "LazyAreas", "{
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LazyComponentFromNuget", "LazyAreas\LazyComponentFromNuget\LazyComponentFromNuget.csproj", "{A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Imports", "Imports", "{7B174F1E-2091-4D48-9111-B52531C1B865}"
+ ProjectSection(SolutionItems) = preProject
+ BlazorLazyLoading.Components.props = BlazorLazyLoading.Components.props
+ BlazorLazyLoading.Module.props = BlazorLazyLoading.Module.props
+ BlazorLazyLoading.Server.props = BlazorLazyLoading.Server.props
+ BlazorLazyLoading.Wasm.props = BlazorLazyLoading.Wasm.props
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -155,6 +165,18 @@ Global
{DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}.Release|x64.Build.0 = Release|Any CPU
{DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}.Release|x86.ActiveCfg = Release|Any CPU
{DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54}.Release|x86.Build.0 = Release|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Debug|x64.Build.0 = Debug|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Debug|x86.Build.0 = Debug|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|x64.ActiveCfg = Release|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|x64.Build.0 = Release|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|x86.ActiveCfg = Release|Any CPU
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -171,6 +193,8 @@ Global
{E503BF43-DE57-4DB6-AF93-A5F765C94154} = {2587AE99-7624-47E4-B6B8-79EC67346F67}
{566D14F1-B2FB-463C-A627-C5EB23B763B7} = {2587AE99-7624-47E4-B6B8-79EC67346F67}
{DB1AE536-72C2-4CCD-A7D9-0A79AAEEDA54} = {2587AE99-7624-47E4-B6B8-79EC67346F67}
+ {A4D17AA8-D918-45FD-9CCA-3FC5ECCDBD97} = {566D14F1-B2FB-463C-A627-C5EB23B763B7}
+ {7B174F1E-2091-4D48-9111-B52531C1B865} = {2587AE99-7624-47E4-B6B8-79EC67346F67}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B979A335-AE81-406A-AADA-F236549D23D3}
diff --git a/demo/LazyAreas/LazyComponentFromNuget/LazyComponentFromNuget.csproj b/demo/LazyAreas/LazyComponentFromNuget/LazyComponentFromNuget.csproj
new file mode 100644
index 0000000..4deafe9
--- /dev/null
+++ b/demo/LazyAreas/LazyComponentFromNuget/LazyComponentFromNuget.csproj
@@ -0,0 +1,19 @@
+
+
+
+ netstandard2.1
+ 3.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/demo/LazyAreas/LazyComponentFromNuget/Pages/LazyComponentFromNuget.razor b/demo/LazyAreas/LazyComponentFromNuget/Pages/LazyComponentFromNuget.razor
new file mode 100644
index 0000000..372a1c7
--- /dev/null
+++ b/demo/LazyAreas/LazyComponentFromNuget/Pages/LazyComponentFromNuget.razor
@@ -0,0 +1,18 @@
+@page "/lazy-component-from-nuget"
+
+
Lazy Component from NuGet
+
+ The following component is rendered from a nuget package (Faso.Blazor.SpinKit in this case).
+ The nuget DLL will only be loaded when opening this page for the first time. Please check the network tab :)
+
+
+@*
+ Works fine out of the box
+*@
+
+
+@*
+ Requires the Module to have:
+ +
+*@
+@**@
diff --git a/demo/LazyAreas/LazyComponentFromNuget/_Imports.razor b/demo/LazyAreas/LazyComponentFromNuget/_Imports.razor
new file mode 100644
index 0000000..c10f507
--- /dev/null
+++ b/demo/LazyAreas/LazyComponentFromNuget/_Imports.razor
@@ -0,0 +1,7 @@
+@using System.Net.Http
+@using Microsoft.AspNetCore.Components.Forms
+@using Microsoft.AspNetCore.Components.Routing
+@using Microsoft.AspNetCore.Components.Web
+@using Microsoft.JSInterop
+
+@using BlazorLazyLoading
diff --git a/demo/LazyAreas/LazyComponentFromNuget/wwwroot/.gitignore b/demo/LazyAreas/LazyComponentFromNuget/wwwroot/.gitignore
new file mode 100644
index 0000000..924b93c
--- /dev/null
+++ b/demo/LazyAreas/LazyComponentFromNuget/wwwroot/.gitignore
@@ -0,0 +1,2 @@
+_lazy/
+_lazy.json
diff --git a/demo/Logger/Logger.csproj b/demo/Logger/Logger.csproj
index 7d8411f..24bde33 100644
--- a/demo/Logger/Logger.csproj
+++ b/demo/Logger/Logger.csproj
@@ -10,15 +10,7 @@
-
-
-
-
-
-
-
-
-
+
diff --git a/demo/ModulesHost/.gitignore b/demo/ModulesHost/.gitignore
new file mode 100644
index 0000000..b498fd4
--- /dev/null
+++ b/demo/ModulesHost/.gitignore
@@ -0,0 +1 @@
+/
diff --git a/demo/ModulesHost/ModulesHost.csproj b/demo/ModulesHost/ModulesHost.csproj
index 6c6d5f4..57fb4e8 100644
--- a/demo/ModulesHost/ModulesHost.csproj
+++ b/demo/ModulesHost/ModulesHost.csproj
@@ -5,21 +5,17 @@
3.0
-
-
-
-
-
-
-
+
+
-
-
-
+
+
+
+
-
-
+
+
diff --git a/demo/ServerHost/ServerHost.csproj b/demo/ServerHost/ServerHost.csproj
index 120ce2b..457139e 100644
--- a/demo/ServerHost/ServerHost.csproj
+++ b/demo/ServerHost/ServerHost.csproj
@@ -4,15 +4,7 @@
netcoreapp3.1
-
-
-
-
-
-
-
-
-
+
diff --git a/demo/WasmHost/Layout/NavMenu.razor b/demo/WasmHost/Layout/NavMenu.razor
index dbdd047..ffab070 100644
--- a/demo/WasmHost/Layout/NavMenu.razor
+++ b/demo/WasmHost/Layout/NavMenu.razor
@@ -14,12 +14,12 @@
- Counter
+ <Lazy />
-
- Fetch Data
+
+ Lazy Component from Nuget
diff --git a/demo/WasmHost/WasmHost.csproj b/demo/WasmHost/WasmHost.csproj
index cc5d03f..2d608ea 100644
--- a/demo/WasmHost/WasmHost.csproj
+++ b/demo/WasmHost/WasmHost.csproj
@@ -10,15 +10,7 @@
-
-
-
-
-
-
-
-
-
+
diff --git a/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.props b/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.props
index 6488b01..edeac9d 100644
--- a/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.props
+++ b/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.props
@@ -1,27 +1,24 @@
- true
+ true
PackageReference
- $(BLLGenerateLazyManifest)
+ $(BLLGenerateManifest)
-
-
-
-
-
+
+
<_BLLNugetPackageBuildBinDirectory>$(MSBuildThisFileDirectory)../build/bin/
- _lazy
- _lazy.json
- $(MSBuildProjectDirectory)/wwwroot/
- $(ModuleWwwRootDirectory)$(ModuleLazyDirectoryName)/
- $(ModuleWwwRootDirectory)$(ModuleLazyManifestFile)
+ <_BLLModuleLazyDirectoryName>_lazy
+ <_BLLModuleLazyManifestFile>_lazy.json
+ <_BLLModuleWwwRootDirectory>$(MSBuildProjectDirectory)/wwwroot/
+ <_BLLModuleLazyDirectory>$(_BLLModuleWwwRootDirectory)$(_BLLModuleLazyDirectoryName)/
+ <_BLLModuleManifestPath>$(_BLLModuleWwwRootDirectory)$(_BLLModuleLazyManifestFile)
diff --git a/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.targets b/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.targets
index a9a88c1..9fdc7d0 100644
--- a/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.targets
+++ b/nuget/BlazorLazyLoading.Module/build/BlazorLazyLoading.Module.targets
@@ -2,19 +2,19 @@
+ Condition="!Exists('$(_BLLModuleWwwRootDirectory).gitignore')"
+ File="$(_BLLModuleWwwRootDirectory).gitignore"
+ Lines="$(_BLLModuleLazyDirectoryName)/;$(_BLLModuleLazyManifestFile)"/>
-
-
+ <_FilesToDelete Include="$(_BLLModuleLazyDirectory)**/*.*" />
+ <_FilesToDelete Include="$(_BLLModuleManifestPath)" />
-
-
+
+
@@ -32,32 +32,28 @@
-
+
-
+
$(MSBuildProjectDirectory)/$(OutDir)
-
-
-
-
-
+
+ AssemblyNames="@(BLLManifestAssemblies)"
+ AssemblyPaths="$(ProjectOutDir);@(BLLManifestAssemblyPaths)"
+ ManifestOutputPath="$(_BLLModuleManifestPath)" />
diff --git a/src/ManifestGenerator/GenerateManifest.cs b/src/ManifestGenerator/GenerateManifest.cs
index 58f1c6a..9b5091f 100644
--- a/src/ManifestGenerator/GenerateManifest.cs
+++ b/src/ManifestGenerator/GenerateManifest.cs
@@ -16,6 +16,8 @@ public class GenerateManifest : Task
{
private readonly ICollection _manifestGenerators;
+ private Logger _logger;
+
[Required]
public string[] AssemblyNames { get; set; } = Array.Empty();
@@ -27,10 +29,12 @@ public class GenerateManifest : Task
public GenerateManifest()
{
+ _logger = new Logger(Log);
+
_manifestGenerators = new IManifestGenerator[]
{
- new ComponentManifestGenerator(),
- new RouteManifestGenerator(),
+ new ComponentManifestGenerator(_logger),
+ new RouteManifestGenerator(_logger),
};
}
@@ -41,21 +45,21 @@ public override bool Execute()
var manifest = new Dictionary();
var dlls = ResolveAvailableDlls().ToList();
- using var dllMetadataContext = CreateDllMetadataContext(dlls);
+ using var metadataLoadContext = CreateDllMetadataLoadContext(dlls);
foreach (string assemblyName in AssemblyNames)
{
try
{
- LogDebug($"Generating manifest for {assemblyName}");
- Assembly assembly = dllMetadataContext.LoadFromAssemblyName(assemblyName);
- LogDebug($"Assembly loaded: {assemblyName}");
+ _logger.Debug($"Generating Manifest file for '{assemblyName}':");
+ Assembly assembly = metadataLoadContext.LoadFromAssemblyName(assemblyName);
+ _logger.Debug($"Assembly loaded: {assemblyName}");
- Dictionary? manifestSections = ExecuteManifestGenerators(assembly);
+ Dictionary? manifestSections = ExecuteManifestGenerators(assembly, metadataLoadContext);
if (manifestSections == null)
{
- LogDebug($"Skipping Lazy Module '{assemblyName}' as it has no relevant manifest sections");
+ _logger.Debug($"Skipping Lazy Module '{assemblyName}' as it has no relevant manifest sections");
continue;
}
@@ -64,11 +68,11 @@ public override bool Execute()
var manifestDescriptions = manifestSections.Select(s =>
"'" + s.Key + "'" + (s.Value is ICollection c ? ": " + c.Count : string.Empty) + "");
- LogInfo($"Lazy Module '{assemblyName}' generated with: {{ {string.Join(", ", manifestDescriptions)} }}");
+ _logger.Info($"Manifest for '{assemblyName}' generated: {{ {string.Join(", ", manifestDescriptions)} }}");
}
catch (Exception ex)
{
- LogError(ex.Message);
+ _logger.Error(ex.Message);
return false;
}
}
@@ -106,19 +110,19 @@ private IEnumerable ResolveAvailableDlls()
.ToList();
}
- private MetadataLoadContext CreateDllMetadataContext(IEnumerable dlls)
+ private MetadataLoadContext CreateDllMetadataLoadContext(IEnumerable dlls)
{
var resolver = new PathAssemblyResolver(dlls);
return new MetadataLoadContext(resolver);
}
- private Dictionary? ExecuteManifestGenerators(Assembly assembly)
+ private Dictionary? ExecuteManifestGenerators(Assembly assembly, MetadataLoadContext metadataLoadContext)
{
var manifestSections = new Dictionary();
foreach (var manifestGenerator in _manifestGenerators)
{
- var manifestSection = manifestGenerator.GenerateManifest(assembly);
+ var manifestSection = manifestGenerator.GenerateManifest(assembly, metadataLoadContext);
if (manifestSection == null)
{
@@ -140,20 +144,5 @@ private MetadataLoadContext CreateDllMetadataContext(IEnumerable dlls)
? manifestSections
: null;
}
-
- private void LogDebug(string message, params object[] args)
- {
- Log.LogMessage(MessageImportance.Normal, message, args);
- }
-
- private void LogInfo(string message, params object[] args)
- {
- Log.LogMessage(MessageImportance.High, message, args);
- }
-
- private void LogError(string message, params object[] args)
- {
- Log.LogError(message, args);
- }
}
}
diff --git a/src/ManifestGenerator/Logger.cs b/src/ManifestGenerator/Logger.cs
new file mode 100644
index 0000000..eb307bd
--- /dev/null
+++ b/src/ManifestGenerator/Logger.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace BlazorLazyLoading
+{
+ public class Logger
+ {
+ private readonly TaskLoggingHelper _logger;
+
+ public Logger(TaskLoggingHelper logger)
+ {
+ _logger = logger;
+ }
+
+ public void Debug(string message, params object[] args)
+ {
+ _logger.LogMessage(MessageImportance.Normal, message, args);
+ }
+
+ public void Info(string message, params object[] args)
+ {
+ _logger.LogMessage(MessageImportance.High, message, args);
+ }
+
+ public void Error(string message, params object[] args)
+ {
+ _logger.LogError(message, args);
+ }
+ }
+}
diff --git a/src/ManifestGenerator/ManifestGenerators/ComponentManifestGenerator.cs b/src/ManifestGenerator/ManifestGenerators/ComponentManifestGenerator.cs
index 91e1f8b..37c9085 100644
--- a/src/ManifestGenerator/ManifestGenerators/ComponentManifestGenerator.cs
+++ b/src/ManifestGenerator/ManifestGenerators/ComponentManifestGenerator.cs
@@ -6,10 +6,17 @@ namespace BlazorLazyLoading.ManifestGenerators
{
public sealed class ComponentManifestGenerator : IManifestGenerator
{
- public Dictionary? GenerateManifest(Assembly assembly)
+ private readonly Logger _logger;
+
+ public ComponentManifestGenerator(Logger logger)
+ {
+ _logger = logger;
+ }
+
+ public Dictionary? GenerateManifest(Assembly assembly, MetadataLoadContext metadataLoadContext)
{
var componentTypes = assembly.GetTypes()
- .Where(t => t.GetInterfaces().Any(i => i.FullName == "Microsoft.AspNetCore.Components.IComponent"));
+ .Where(t => !t.IsAbstract && t.GetInterfaces().Any(i => i.FullName == "Microsoft.AspNetCore.Components.IComponent"));
var components = new List();
diff --git a/src/ManifestGenerator/ManifestGenerators/IManifestGenerator.cs b/src/ManifestGenerator/ManifestGenerators/IManifestGenerator.cs
index 8ff5603..8a3c785 100644
--- a/src/ManifestGenerator/ManifestGenerators/IManifestGenerator.cs
+++ b/src/ManifestGenerator/ManifestGenerators/IManifestGenerator.cs
@@ -5,6 +5,6 @@ namespace BlazorLazyLoading
{
public interface IManifestGenerator
{
- public Dictionary? GenerateManifest(Assembly assembly);
+ public Dictionary? GenerateManifest(Assembly assembly, MetadataLoadContext metadataLoadContext);
}
}
diff --git a/src/ManifestGenerator/ManifestGenerators/RouteManifestGenerator.cs b/src/ManifestGenerator/ManifestGenerators/RouteManifestGenerator.cs
index 8db4526..8ba5ebf 100644
--- a/src/ManifestGenerator/ManifestGenerators/RouteManifestGenerator.cs
+++ b/src/ManifestGenerator/ManifestGenerators/RouteManifestGenerator.cs
@@ -6,10 +6,17 @@ namespace BlazorLazyLoading.ManifestGenerators
{
public sealed class RouteManifestGenerator : IManifestGenerator
{
- public Dictionary? GenerateManifest(Assembly assembly)
+ private readonly Logger _logger;
+
+ public RouteManifestGenerator(Logger logger)
+ {
+ _logger = logger;
+ }
+
+ public Dictionary? GenerateManifest(Assembly assembly, MetadataLoadContext metadataLoadContext)
{
var componentTypes = assembly.GetTypes()
- .Where(t => t.GetInterfaces().Any(i => i.FullName == "Microsoft.AspNetCore.Components.IComponent"));
+ .Where(t => !t.IsAbstract && t.GetInterfaces().Any(i => i.FullName == "Microsoft.AspNetCore.Components.IComponent"));
var routes = componentTypes.SelectMany(t => t.GetCustomAttributesData()
.Where(a => a.AttributeType.FullName == "Microsoft.AspNetCore.Components.RouteAttribute")