diff --git a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs index 3a2ccfbaaee2..e4d51e992c5b 100644 --- a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs +++ b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs @@ -19,6 +19,10 @@ internal class WebAssemblyHost : IWebAssemblyHost public WebAssemblyHost(IServiceProvider services, IJSRuntime runtime) { + // To ensure [JSInterop] methods don't get linked out, have a reference to their enclosing types + GC.KeepAlive(typeof(JSInteropMethods)); + GC.KeepAlive(typeof(WebAssemblyEventDispatcher)); + Services = services ?? throw new ArgumentNullException(nameof(services)); _runtime = runtime ?? throw new ArgumentNullException(nameof(runtime)); } diff --git a/src/Components/Blazor/Build/src/Tasks/BlazorILLink.cs b/src/Components/Blazor/Build/src/Tasks/BlazorILLink.cs index 5e0a86d384e4..440af669268a 100644 --- a/src/Components/Blazor/Build/src/Tasks/BlazorILLink.cs +++ b/src/Components/Blazor/Build/src/Tasks/BlazorILLink.cs @@ -112,6 +112,14 @@ protected override string GenerateResponseFileCommands() args.Append(action); args.Append(" ").AppendLine(Quote(assemblyName)); } + + var actionflag = assembly.GetMetadata("actionflag"); + if ((actionflag != null) && (actionflag.Length > 0)) + { + args.Append("-f "); + args.Append(actionflag); + args.Append(" ").AppendLine(Quote(assemblyName)); + } } if (ReferenceAssemblyPaths != null) diff --git a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets index 0a3ba70a2374..8be31d973a04 100644 --- a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets +++ b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets @@ -171,7 +171,10 @@ Outputs="$(_BlazorLinkerOutputCache)"> - <_BlazorDependencyAssembly Include="@(_BlazorDependencyInput)" IsLinkable="$([System.String]::Copy('%(FileName)').StartsWith('System.'))" /> + <_BlazorDependencyAssembly Include="@(_BlazorDependencyInput)" /> + <_BlazorDependencyAssembly IsLinkable="true" Condition="$([System.String]::Copy(%(Filename)).StartsWith('System.'))" /> + <_BlazorDependencyAssembly IsLinkable="true" ActionFlag="TypeGranularity" Condition="$([System.String]::Copy(%(Filename)).StartsWith('Microsoft.AspNetCore.'))" /> + <_BlazorDependencyAssembly IsLinkable="true" Condition="$([System.String]::Copy(%(Filename)).StartsWith('Microsoft.Extensions.'))" /> <_BlazorAssemblyToLink Include="@(_WebAssemblyBCLAssembly)" /> <_BlazorAssemblyToLink Include="@(_BlazorDependencyAssembly)" Condition="'%(_BlazorDependencyAssembly.IsLinkable)' == 'true'" />