Skip to content

Commit c4efbfb

Browse files
authored
Trim Microsoft.AspNetCore (#42555)
1 parent 45c7d3c commit c4efbfb

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

eng/TrimmableProjects.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-->
88
<Project>
99
<ItemGroup>
10+
<TrimmableProject Include="Microsoft.AspNetCore" />
1011
<TrimmableProject Include="Microsoft.AspNetCore.DataProtection.Abstractions" />
1112
<TrimmableProject Include="Microsoft.AspNetCore.Cryptography.Internal" />
1213
<TrimmableProject Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" />

src/DefaultBuilder/src/ConfigureWebHostBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ IWebHostBuilder ISupportsStartup.Configure(Action<WebHostBuilderContext, IApplic
173173
throw new NotSupportedException("Configure() is not supported by WebApplicationBuilder.WebHost. Use the WebApplication returned by WebApplicationBuilder.Build() instead.");
174174
}
175175

176-
IWebHostBuilder ISupportsStartup.UseStartup(Type startupType)
176+
IWebHostBuilder ISupportsStartup.UseStartup([DynamicallyAccessedMembers(StartupLinkerOptions.Accessibility)] Type startupType)
177177
{
178178
throw new NotSupportedException("UseStartup() is not supported by WebApplicationBuilder.WebHost. Use the WebApplication returned by WebApplicationBuilder.Build() instead.");
179179
}

src/DefaultBuilder/src/Microsoft.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Description>Microsoft.AspNetCore</Description>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<IsPackable>false</IsPackable>
10-
<Nullable>enable</Nullable>
10+
<IsTrimmable>true</IsTrimmable>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace Microsoft.AspNetCore;
7+
8+
internal static class StartupLinkerOptions
9+
{
10+
// We're going to keep all public constructors and public methods on Startup classes
11+
public const DynamicallyAccessedMemberTypes Accessibility = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicMethods;
12+
}

src/DefaultBuilder/src/WebHost.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using System.Reflection;
56
using Microsoft.AspNetCore.Builder;
67
using Microsoft.AspNetCore.HostFiltering;
@@ -269,6 +270,6 @@ internal static void ConfigureWebDefaults(IWebHostBuilder builder)
269270
/// <typeparam name ="TStartup">The type containing the startup methods for the application.</typeparam>
270271
/// <param name="args">The command line args.</param>
271272
/// <returns>The initialized <see cref="IWebHostBuilder"/>.</returns>
272-
public static IWebHostBuilder CreateDefaultBuilder<TStartup>(string[] args) where TStartup : class =>
273+
public static IWebHostBuilder CreateDefaultBuilder<[DynamicallyAccessedMembers(StartupLinkerOptions.Accessibility)] TStartup>(string[] args) where TStartup : class =>
273274
CreateDefaultBuilder(args).UseStartup<TStartup>();
274275
}

src/Tools/Tools.slnf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"src\\Antiforgery\\src\\Microsoft.AspNetCore.Antiforgery.csproj",
66
"src\\Components\\Authorization\\src\\Microsoft.AspNetCore.Components.Authorization.csproj",
77
"src\\Components\\Components\\src\\Microsoft.AspNetCore.Components.csproj",
8+
"src\\Components\\CustomElements\\src\\Microsoft.AspNetCore.Components.CustomElements.csproj",
89
"src\\Components\\Forms\\src\\Microsoft.AspNetCore.Components.Forms.csproj",
910
"src\\Components\\WebAssembly\\Authentication.Msal\\src\\Microsoft.Authentication.WebAssembly.Msal.csproj",
1011
"src\\Components\\WebAssembly\\JSInterop\\src\\Microsoft.JSInterop.WebAssembly.csproj",
@@ -18,6 +19,7 @@
1819
"src\\DataProtection\\EntityFrameworkCore\\src\\Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.csproj",
1920
"src\\DataProtection\\Extensions\\src\\Microsoft.AspNetCore.DataProtection.Extensions.csproj",
2021
"src\\DataProtection\\StackExchangeRedis\\src\\Microsoft.AspNetCore.DataProtection.StackExchangeRedis.csproj",
22+
"src\\DefaultBuilder\\src\\Microsoft.AspNetCore.csproj",
2123
"src\\Extensions\\Features\\src\\Microsoft.Extensions.Features.csproj",
2224
"src\\HealthChecks\\Abstractions\\src\\Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.csproj",
2325
"src\\HealthChecks\\HealthChecks\\src\\Microsoft.Extensions.Diagnostics.HealthChecks.csproj",
@@ -52,6 +54,7 @@
5254
"src\\Middleware\\Localization.Routing\\src\\Microsoft.AspNetCore.Localization.Routing.csproj",
5355
"src\\Middleware\\Localization\\src\\Microsoft.AspNetCore.Localization.csproj",
5456
"src\\Middleware\\MiddlewareAnalysis\\src\\Microsoft.AspNetCore.MiddlewareAnalysis.csproj",
57+
"src\\Middleware\\OutputCaching\\src\\Microsoft.AspNetCore.OutputCaching.csproj",
5558
"src\\Middleware\\RateLimiting\\src\\Microsoft.AspNetCore.RateLimiting.csproj",
5659
"src\\Middleware\\RequestDecompression\\src\\Microsoft.AspNetCore.RequestDecompression.csproj",
5760
"src\\Middleware\\ResponseCaching.Abstractions\\src\\Microsoft.AspNetCore.ResponseCaching.Abstractions.csproj",

0 commit comments

Comments
 (0)