From d4ada348fba375f3f77ed8ed65d834155ae746f6 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 7 Jan 2020 13:42:25 -0800 Subject: [PATCH 1/9] Use Blazor version for WASM templates (#18174) --- src/Components/Blazor/Blazor.Version.props | 8 ++++++++ src/Components/Blazor/Directory.Build.props | 5 +---- .../Microsoft.AspNetCore.Blazor.Templates.csproj | 8 ++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/Components/Blazor/Blazor.Version.props diff --git a/src/Components/Blazor/Blazor.Version.props b/src/Components/Blazor/Blazor.Version.props new file mode 100644 index 0000000000..123a94c1d7 --- /dev/null +++ b/src/Components/Blazor/Blazor.Version.props @@ -0,0 +1,8 @@ + + + + 3.2.0 + preview1 + + + \ No newline at end of file diff --git a/src/Components/Blazor/Directory.Build.props b/src/Components/Blazor/Directory.Build.props index 59beb90ee9..8df2e791dd 100644 --- a/src/Components/Blazor/Directory.Build.props +++ b/src/Components/Blazor/Directory.Build.props @@ -1,11 +1,8 @@ + - - 3.2.0 - preview1 - 3.1.0 diff --git a/src/ProjectTemplates/BlazorWasm.ProjectTemplates/Microsoft.AspNetCore.Blazor.Templates.csproj b/src/ProjectTemplates/BlazorWasm.ProjectTemplates/Microsoft.AspNetCore.Blazor.Templates.csproj index 32c3197d04..65457a000d 100644 --- a/src/ProjectTemplates/BlazorWasm.ProjectTemplates/Microsoft.AspNetCore.Blazor.Templates.csproj +++ b/src/ProjectTemplates/BlazorWasm.ProjectTemplates/Microsoft.AspNetCore.Blazor.Templates.csproj @@ -1,4 +1,10 @@  + + $(RepoRoot)src\Components\Blazor\ + + + + $(DefaultNetCoreTargetFramework) true @@ -18,8 +24,6 @@ MicrosoftEntityFrameworkCoreSqlServerPackageVersion=$(MicrosoftEntityFrameworkCoreSqlServerPackageVersion); MicrosoftAspNetCoreBlazorServerPackageVersion=$(MicrosoftAspNetCoreBlazorServerPackageVersion); - - $(RepoRoot)src\Components\Blazor\ From a181fd52326e383d33bd36be6e799f31720a823d Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Fri, 10 Jan 2020 11:30:55 +0000 Subject: [PATCH 2/9] Link more assemblies (type granularity linking for real this time) (#18165) --- .../Blazor/src/Hosting/WebAssemblyHost.cs | 5 ++ .../GenerateTypeGranularityLinkingConfig.cs | 48 +++++++++++++++++++ .../src/targets/Blazor.MonoRuntime.targets | 15 +++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/Components/Blazor/Build/src/Tasks/GenerateTypeGranularityLinkingConfig.cs diff --git a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs index 3a2ccfbaae..b90878fdde 100644 --- a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs +++ b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs @@ -19,6 +19,11 @@ namespace Microsoft.AspNetCore.Blazor.Hosting public WebAssemblyHost(IServiceProvider services, IJSRuntime runtime) { + // To ensure JS-invoked methods don't get linked out, have a reference to their enclosing types + GC.KeepAlive(typeof(EntrypointInvoker)); + 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/GenerateTypeGranularityLinkingConfig.cs b/src/Components/Blazor/Build/src/Tasks/GenerateTypeGranularityLinkingConfig.cs new file mode 100644 index 0000000000..8a56b7fc3d --- /dev/null +++ b/src/Components/Blazor/Build/src/Tasks/GenerateTypeGranularityLinkingConfig.cs @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Xml.Linq; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Microsoft.AspNetCore.Blazor.Build.Tasks +{ + public class GenerateTypeGranularityLinkingConfig : Task + { + [Required] + public ITaskItem[] Assemblies { get; set; } + + [Required] + public string OutputPath { get; set; } + + public override bool Execute() + { + var linkerElement = new XElement("linker", + new XComment(" THIS IS A GENERATED FILE - DO NOT EDIT MANUALLY ")); + + foreach (var assembly in Assemblies) + { + var assemblyElement = CreateTypeGranularityConfig(assembly); + linkerElement.Add(assemblyElement); + } + + using var fileStream = File.Open(OutputPath, FileMode.Create); + new XDocument(linkerElement).Save(fileStream); + + return true; + } + + private XElement CreateTypeGranularityConfig(ITaskItem assembly) + { + // We match all types in the assembly, and for each one, tell the linker to preserve all + // its members (preserve=all) but only if there's some reference to the type (required=false) + return new XElement("assembly", + new XAttribute("fullname", Path.GetFileNameWithoutExtension(assembly.ItemSpec)), + new XElement("type", + new XAttribute("fullname", "*"), + new XAttribute("preserve", "all"), + new XAttribute("required", "false"))); + } + } +} diff --git a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets index 0a3ba70a23..4bdb2f4311 100644 --- a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets +++ b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets @@ -160,6 +160,7 @@ + - <_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" TypeGranularity="true" Condition="$([System.String]::Copy('%(Filename)').StartsWith('Microsoft.AspNetCore.'))" /> + <_BlazorDependencyAssembly IsLinkable="true" TypeGranularity="true" Condition="$([System.String]::Copy('%(Filename)').StartsWith('Microsoft.Extensions.'))" /> <_BlazorAssemblyToLink Include="@(_WebAssemblyBCLAssembly)" /> <_BlazorAssemblyToLink Include="@(_BlazorDependencyAssembly)" Condition="'%(_BlazorDependencyAssembly.IsLinkable)' == 'true'" /> @@ -201,6 +205,15 @@ <_DotNetHostFileName Condition=" '$(OS)' == 'Windows_NT' ">dotnet.exe + + <_TypeGranularityLinkingConfig>$(BlazorIntermediateOutputPath)linker.typegranularityconfig.xml + + + + + + + Date: Thu, 9 Jan 2020 15:46:25 +0000 Subject: [PATCH 3/9] Allow overwriting outputs with older inputs. Fixes #18192 --- .../Blazor/Build/src/targets/Blazor.MonoRuntime.targets | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets index 4bdb2f4311..24378975a0 100644 --- a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets +++ b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets @@ -22,8 +22,6 @@ From 2e2d0625e14d20c4f222affa5bfc20d761c89c54 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 9 Jan 2020 15:46:51 +0000 Subject: [PATCH 4/9] Write unlinked.output to disk --- .../Blazor/Build/src/targets/Blazor.MonoRuntime.targets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets index 24378975a0..cdbe7169a0 100644 --- a/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets +++ b/src/Components/Blazor/Build/src/targets/Blazor.MonoRuntime.targets @@ -268,6 +268,8 @@ + + From 524fb297cc9fd4bc366be2b3c9e379efc8d1ae35 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 15 Jan 2020 08:49:49 -0800 Subject: [PATCH 5/9] Update Blazor.Version.props --- src/Components/Blazor/Blazor.Version.props | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Components/Blazor/Blazor.Version.props b/src/Components/Blazor/Blazor.Version.props index 123a94c1d7..8b13789179 100644 --- a/src/Components/Blazor/Blazor.Version.props +++ b/src/Components/Blazor/Blazor.Version.props @@ -1,8 +1 @@ - - - - 3.2.0 - preview1 - - - \ No newline at end of file + From 7fa94800ff4cf270ace3941dd3a7f7c1c454a034 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 15 Jan 2020 08:50:02 -0800 Subject: [PATCH 6/9] Update Directory.Build.props --- src/Components/Blazor/Directory.Build.props | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Components/Blazor/Directory.Build.props b/src/Components/Blazor/Directory.Build.props index 8df2e791dd..8b13789179 100644 --- a/src/Components/Blazor/Directory.Build.props +++ b/src/Components/Blazor/Directory.Build.props @@ -1,10 +1 @@ - - - - - - 3.1.0 - - From f0c991d37342324759bb77377cddeb769a8da845 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 15 Jan 2020 08:54:41 -0800 Subject: [PATCH 7/9] Update Blazor.Version.props --- src/Components/Blazor/Blazor.Version.props | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/Blazor/Blazor.Version.props b/src/Components/Blazor/Blazor.Version.props index 8b13789179..8c119d5413 100644 --- a/src/Components/Blazor/Blazor.Version.props +++ b/src/Components/Blazor/Blazor.Version.props @@ -1 +1,2 @@ - + + From 454faf9fc11d419a5db58575429f53ae0326e73d Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 15 Jan 2020 08:54:54 -0800 Subject: [PATCH 8/9] Update Directory.Build.props --- src/Components/Blazor/Directory.Build.props | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/Blazor/Directory.Build.props b/src/Components/Blazor/Directory.Build.props index 8b13789179..8c119d5413 100644 --- a/src/Components/Blazor/Directory.Build.props +++ b/src/Components/Blazor/Directory.Build.props @@ -1 +1,2 @@ - + + From ab600289aa832c7e19308eb982e666b5804b8d37 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Wed, 15 Jan 2020 09:04:57 -0800 Subject: [PATCH 9/9] Update Directory.Build.props --- src/Components/Blazor/Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Components/Blazor/Directory.Build.props b/src/Components/Blazor/Directory.Build.props index 8c119d5413..c48cf8a1a9 100644 --- a/src/Components/Blazor/Directory.Build.props +++ b/src/Components/Blazor/Directory.Build.props @@ -1,2 +1,3 @@ +