Просмотр исходного кода

Annotate Http.Connections for trimming (#52918)

Brennan 2 лет назад
Родитель
Сommit
cba30028d2

+ 3 - 0
eng/TrimmableProjects.props

@@ -85,6 +85,9 @@
     <TrimmableProject Include="Microsoft.AspNetCore.SpaServices.Extensions" />
     <TrimmableProject Include="Microsoft.AspNetCore.StaticFiles" />
     <TrimmableProject Include="Microsoft.AspNetCore.WebSockets" />
+    <TrimmableProject Include="Microsoft.AspNetCore.Http.Connections.Common" />
+    <TrimmableProject Include="Microsoft.AspNetCore.Http.Connections" />
+    <TrimmableProject Include="Microsoft.AspNetCore.SignalR.Common" />
     <TrimmableProject Include="Microsoft.AspNetCore.Components.Authorization" />
     <TrimmableProject Include="Microsoft.AspNetCore.Components" />
     <TrimmableProject Include="Microsoft.AspNetCore.Components.CustomElements" />

+ 5 - 0
src/Shared/CodeAnalysis/DynamicallyAccessedMemberTypes.cs

@@ -86,6 +86,11 @@ internal enum DynamicallyAccessedMemberTypes
     /// </summary>
     NonPublicEvents = 0x1000,
 
+    /// <summary>
+    /// Specifies all interfaces implemented by the type.
+    /// </summary>
+    Interfaces = 0x2000,
+
     /// <summary>
     /// Specifies all members.
     /// </summary>

+ 2 - 0
src/SignalR/clients/csharp/Client.Core/src/Microsoft.AspNetCore.SignalR.Client.Core.csproj

@@ -19,6 +19,8 @@
     <Compile Include="$(SharedSourceRoot)ThrowHelpers\ArgumentNullThrowHelper.cs" LinkBase="Shared" />
     <Compile Include="$(SharedSourceRoot)ThrowHelpers\ObjectDisposedThrowHelper.cs" LinkBase="Shared" />
     <Compile Include="$(SharedSourceRoot)CallerArgument\CallerArgumentExpressionAttribute.cs" LinkBase="Shared" />
+    <Compile Include="$(SharedSourceRoot)CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" LinkBase="Shared" />
+    <Compile Include="$(SharedSourceRoot)CodeAnalysis\DynamicallyAccessedMemberTypes.cs" LinkBase="Shared" />
   </ItemGroup>
 
   <ItemGroup>

+ 1 - 0
src/SignalR/common/Http.Connections.Common/src/Microsoft.AspNetCore.Http.Connections.Common.csproj

@@ -8,6 +8,7 @@
     <RootNamespace>Microsoft.AspNetCore.Http.Connections</RootNamespace>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <Nullable>enable</Nullable>
+    <IsTrimmable>true</IsTrimmable>
   </PropertyGroup>
 
   <ItemGroup>

+ 2 - 2
src/SignalR/common/Http.Connections/src/ConnectionEndpointRouteBuilderExtensions.cs

@@ -35,7 +35,7 @@ public static class ConnectionEndpointRouteBuilderExtensions
     /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
     /// <param name="pattern">The route pattern.</param>
     /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
-    public static ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern) where TConnectionHandler : ConnectionHandler
+    public static ConnectionEndpointRouteBuilder MapConnectionHandler<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern) where TConnectionHandler : ConnectionHandler
     {
         return endpoints.MapConnectionHandler<TConnectionHandler>(pattern, configureOptions: null);
     }
@@ -48,7 +48,7 @@ public static class ConnectionEndpointRouteBuilderExtensions
     /// <param name="pattern">The route pattern.</param>
     /// <param name="configureOptions">A callback to configure dispatcher options.</param>
     /// <returns>An <see cref="ConnectionEndpointRouteBuilder"/> for endpoints associated with the connections.</returns>
-    public static ConnectionEndpointRouteBuilder MapConnectionHandler<TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Action<HttpConnectionDispatcherOptions>? configureOptions) where TConnectionHandler : ConnectionHandler
+    public static ConnectionEndpointRouteBuilder MapConnectionHandler<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TConnectionHandler>(this IEndpointRouteBuilder endpoints, [StringSyntax("Route")] string pattern, Action<HttpConnectionDispatcherOptions>? configureOptions) where TConnectionHandler : ConnectionHandler
     {
         var options = new HttpConnectionDispatcherOptions();
         configureOptions?.Invoke(options);

+ 1 - 0
src/SignalR/common/Http.Connections/src/Microsoft.AspNetCore.Http.Connections.csproj

@@ -7,6 +7,7 @@
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <IsPackable>false</IsPackable>
     <Nullable>enable</Nullable>
+    <IsTrimmable>true</IsTrimmable>
   </PropertyGroup>
 
   <ItemGroup>

+ 3 - 2
src/SignalR/common/Shared/ReflectionHelper.cs

@@ -3,6 +3,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Linq;
 using System.Threading.Channels;
 
@@ -12,7 +13,7 @@ internal static class ReflectionHelper
 {
     // mustBeDirectType - Hub methods must use the base 'stream' type and not be a derived class that just implements the 'stream' type
     // and 'stream' types from the client are allowed to inherit from accepted 'stream' types
-    public static bool IsStreamingType(Type type, bool mustBeDirectType = false)
+    public static bool IsStreamingType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type, bool mustBeDirectType = false)
     {
         // TODO #2594 - add Streams here, to make sending files easy
 
@@ -36,7 +37,7 @@ internal static class ReflectionHelper
         return false;
     }
 
-    public static bool IsIAsyncEnumerable(Type type)
+    public static bool IsIAsyncEnumerable([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)] Type type)
     {
         if (type.IsGenericType)
         {

+ 2 - 1
src/SignalR/common/SignalR.Common/src/Microsoft.AspNetCore.SignalR.Common.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <Description>Common serialization primitives for SignalR Clients Servers</Description>
@@ -8,6 +8,7 @@
     <RootNamespace>Microsoft.AspNetCore.SignalR</RootNamespace>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <Nullable>enable</Nullable>
+    <IsTrimmable>true</IsTrimmable>
   </PropertyGroup>
 
   <ItemGroup>

+ 3 - 0
src/Tools/Tools.slnf

@@ -100,6 +100,9 @@
       "src\\Servers\\Kestrel\\Transport.NamedPipes\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.csproj",
       "src\\Servers\\Kestrel\\Transport.Quic\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Quic.csproj",
       "src\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj",
+      "src\\SignalR\\common\\Http.Connections.Common\\src\\Microsoft.AspNetCore.Http.Connections.Common.csproj",
+      "src\\SignalR\\common\\Http.Connections\\src\\Microsoft.AspNetCore.Http.Connections.csproj",
+      "src\\SignalR\\common\\SignalR.Common\\src\\Microsoft.AspNetCore.SignalR.Common.csproj",
       "src\\Testing\\src\\Microsoft.AspNetCore.InternalTesting.csproj",
       "src\\Tools\\Extensions.ApiDescription.Client\\src\\Microsoft.Extensions.ApiDescription.Client.csproj",
       "src\\Tools\\Extensions.ApiDescription.Client\\test\\Microsoft.Extensions.ApiDescription.Client.Tests.csproj",