Enable trimming for Microsoft.Extensions packages (#24986)
* Enable trimming for Microsoft.Extensions packages Fixes https://github.com/dotnet/aspnetcore/issues/24634 * Update Microsoft.NET.Sdk.BlazorWebAssembly.csproj * Apply suggestions from code review * Fixup test
This commit is contained in:
parent
187eacd570
commit
d2f34d6d99
|
|
@ -141,8 +141,6 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
serviceWorkerPath: Path.Combine("serviceworkers", "my-service-worker.js"),
|
serviceWorkerPath: Path.Combine("serviceworkers", "my-service-worker.js"),
|
||||||
serviceWorkerContent: "// This is the production service worker",
|
serviceWorkerContent: "// This is the production service worker",
|
||||||
assetsManifestPath: "custom-service-worker-assets.js");
|
assetsManifestPath: "custom-service-worker-assets.js");
|
||||||
|
|
||||||
VerifyTypeGranularTrimming(result, blazorPublishDirectory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -906,16 +904,17 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
||||||
|
|
||||||
private void VerifyTypeGranularTrimming(MSBuildResult result, string blazorPublishDirectory)
|
private void VerifyTypeGranularTrimming(MSBuildResult result, string blazorPublishDirectory)
|
||||||
{
|
{
|
||||||
var loggingAssemblyPath = Path.Combine(blazorPublishDirectory, "_framework", "Microsoft.Extensions.Logging.Abstractions.dll");
|
var componentsShimAssemblyPath = Path.Combine(blazorPublishDirectory, "_framework", "Microsoft.AspNetCore.Razor.Test.ComponentShim.dll");
|
||||||
Assert.FileExists(result, loggingAssemblyPath);
|
Assert.FileExists(result, componentsShimAssemblyPath);
|
||||||
|
|
||||||
// ILogger is referenced by the app, so we expect it to be preserved
|
// RouteView is referenced by the app, so we expect it to be preserved
|
||||||
Assert.AssemblyContainsType(result, loggingAssemblyPath, "Microsoft.Extensions.Logging.ILogger");
|
Assert.AssemblyContainsType(result, componentsShimAssemblyPath, "Microsoft.AspNetCore.Components.RouteView");
|
||||||
// LogLevel is referenced by ILogger and therefore must be preserved.
|
|
||||||
Assert.AssemblyContainsType(result, loggingAssemblyPath, "Microsoft.Extensions.Logging.LogLevel");
|
|
||||||
|
|
||||||
// NullLogger is not referenced by the app, and should be trimmed.
|
// RouteData is referenced by RouteView so we expect it to be preserved.
|
||||||
Assert.AssemblyDoesNotContainType(result, loggingAssemblyPath, "Microsoft.Extensions.Logging.Abstractions.NullLogger");
|
Assert.AssemblyContainsType(result, componentsShimAssemblyPath, "Microsoft.AspNetCore.Components.RouteData");
|
||||||
|
|
||||||
|
// CascadingParameterAttribute is not referenced by the app, and should be trimmed.
|
||||||
|
Assert.AssemblyDoesNotContainType(result, componentsShimAssemblyPath, "Microsoft.AspNetCore.Components.CascadingParameterAttribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BootJsonData ReadBootJsonData(MSBuildResult result, string path)
|
private static BootJsonData ReadBootJsonData(MSBuildResult result, string path)
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,7 @@ Copyright (c) .NET Foundation. All rights reserved.
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<_BlazorTypeGranularAssembly
|
<_BlazorTypeGranularAssembly
|
||||||
Include="@(ManagedAssemblyToLink)"
|
Include="@(ManagedAssemblyToLink)"
|
||||||
Condition="'%(Extension)' == '.dll' AND ($([System.String]::Copy('%(Filename)').StartsWith('Microsoft.AspNetCore.')) or $([System.String]::Copy('%(Filename)').StartsWith('Microsoft.Extensions.')))">
|
Condition="'%(Extension)' == '.dll' AND $([System.String]::Copy('%(Filename)').StartsWith('Microsoft.AspNetCore.'))">
|
||||||
<Required>false</Required>
|
<Required>false</Required>
|
||||||
<Preserve>all</Preserve>
|
<Preserve>all</Preserve>
|
||||||
</_BlazorTypeGranularAssembly>
|
</_BlazorTypeGranularAssembly>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ namespace standalone
|
||||||
{
|
{
|
||||||
GC.KeepAlive(typeof(System.Text.Json.JsonSerializer));
|
GC.KeepAlive(typeof(System.Text.Json.JsonSerializer));
|
||||||
GC.KeepAlive(typeof(RazorClassLibrary.Class1));
|
GC.KeepAlive(typeof(RazorClassLibrary.Class1));
|
||||||
GC.KeepAlive(typeof(Microsoft.Extensions.Logging.ILogger));
|
|
||||||
#if REFERENCE_classlibrarywithsatelliteassemblies
|
#if REFERENCE_classlibrarywithsatelliteassemblies
|
||||||
GC.KeepAlive(typeof(classlibrarywithsatelliteassemblies.Class1));
|
GC.KeepAlive(typeof(classlibrarywithsatelliteassemblies.Class1));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue