Skip to content

Commit 656f091

Browse files
authored
Add [RequiresUnreferencedCode] attribute to top level APIs. (#47663)
* Add [RequiresUnreferencedCode] attribute to top level APIs.
1 parent 53b9175 commit 656f091

File tree

8 files changed

+25
-0
lines changed

8 files changed

+25
-0
lines changed

src/Components/Endpoints/src/DependencyInjection/RazorComponentsServiceCollectionExtensions.cs

Lines changed: 2 additions & 0 deletions
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 Microsoft.AspNetCore.Components;
56
using Microsoft.AspNetCore.Components.Endpoints;
67
using Microsoft.AspNetCore.Components.Infrastructure;
@@ -23,6 +24,7 @@ public static class RazorComponentsServiceCollectionExtensions
2324
/// </summary>
2425
/// <param name="services">The service collection.</param>
2526
/// <returns>A builder for configuring the Razor Components endpoints.</returns>
27+
[RequiresUnreferencedCode("Razor Components does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
2628
public static IRazorComponentsBuilder AddRazorComponents(this IServiceCollection services)
2729
{
2830
services.TryAddSingleton<RazorComponentsMarkerService>();

src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs

Lines changed: 2 additions & 0 deletions
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 Microsoft.AspNetCore.Components;
56
using Microsoft.AspNetCore.Components.Authorization;
67
using Microsoft.AspNetCore.Components.Routing;
@@ -27,6 +28,7 @@ public static class ComponentServiceCollectionExtensions
2728
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
2829
/// <param name="configure">A callback to configure <see cref="CircuitOptions"/>.</param>
2930
/// <returns>An <see cref="IServerSideBlazorBuilder"/> that can be used to further customize the configuration.</returns>
31+
[RequiresUnreferencedCode("Server-side Blazor does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
3032
public static IServerSideBlazorBuilder AddServerSideBlazor(this IServiceCollection services, Action<CircuitOptions>? configure = null)
3133
{
3234
var builder = new DefaultServerSideBlazorBuilder(services);

src/Identity/Core/src/IdentityServiceCollectionExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static class IdentityServiceCollectionExtensions
2121
/// <typeparam name="TRole">The type representing a Role in the system.</typeparam>
2222
/// <param name="services">The services available in the application.</param>
2323
/// <returns>An <see cref="IdentityBuilder"/> for creating and configuring the identity system.</returns>
24+
[RequiresUnreferencedCode("Identity middleware does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
2425
public static IdentityBuilder AddIdentity<TUser, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TRole>(
2526
this IServiceCollection services)
2627
where TUser : class
@@ -35,6 +36,7 @@ public static class IdentityServiceCollectionExtensions
3536
/// <param name="services">The services available in the application.</param>
3637
/// <param name="setupAction">An action to configure the <see cref="IdentityOptions"/>.</param>
3738
/// <returns>An <see cref="IdentityBuilder"/> for creating and configuring the identity system.</returns>
39+
[RequiresUnreferencedCode("Identity middleware does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
3840
public static IdentityBuilder AddIdentity<TUser, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TRole>(
3941
this IServiceCollection services,
4042
Action<IdentityOptions> setupAction)

src/Middleware/Session/src/SessionServiceCollectionExtensions.cs

Lines changed: 3 additions & 0 deletions
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 Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.Session;
67
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -17,6 +18,7 @@ public static class SessionServiceCollectionExtensions
1718
/// </summary>
1819
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
1920
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
21+
[RequiresUnreferencedCode("Session State middleware does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
2022
public static IServiceCollection AddSession(this IServiceCollection services)
2123
{
2224
ArgumentNullException.ThrowIfNull(services);
@@ -32,6 +34,7 @@ public static IServiceCollection AddSession(this IServiceCollection services)
3234
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
3335
/// <param name="configure">The session options to configure the middleware with.</param>
3436
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
37+
[RequiresUnreferencedCode("Session State middleware does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
3538
public static IServiceCollection AddSession(this IServiceCollection services, Action<SessionOptions> configure)
3639
{
3740
ArgumentNullException.ThrowIfNull(services);

src/Mvc/Mvc.RazorPages/src/DependencyInjection/MvcRazorPagesMvcCoreBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
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.Linq;
56
using Microsoft.AspNetCore.Mvc.Abstractions;
67
using Microsoft.AspNetCore.Mvc.ApplicationModels;
@@ -26,6 +27,7 @@ public static class MvcRazorPagesMvcCoreBuilderExtensions
2627
/// </summary>
2728
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
2829
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
30+
[RequiresUnreferencedCode("Razor Pages does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
2931
public static IMvcCoreBuilder AddRazorPages(this IMvcCoreBuilder builder)
3032
{
3133
ArgumentNullException.ThrowIfNull(builder);

src/Mvc/Mvc/src/MvcServiceCollectionExtensions.cs

Lines changed: 7 additions & 0 deletions
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.Diagnostics;
56
using System.Linq;
67
using System.Reflection;
@@ -76,6 +77,7 @@ public static IMvcBuilder AddMvc(this IServiceCollection services, Action<MvcOpt
7677
/// on the resulting builder.
7778
/// </para>
7879
/// </remarks>
80+
[RequiresUnreferencedCode("MVC does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
7981
public static IMvcBuilder AddControllers(this IServiceCollection services)
8082
{
8183
ArgumentNullException.ThrowIfNull(services);
@@ -110,6 +112,7 @@ public static IMvcBuilder AddControllers(this IServiceCollection services)
110112
/// on the resulting builder.
111113
/// </para>
112114
/// </remarks>
115+
[RequiresUnreferencedCode("MVC does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
113116
public static IMvcBuilder AddControllers(this IServiceCollection services, Action<MvcOptions>? configure)
114117
{
115118
ArgumentNullException.ThrowIfNull(services);
@@ -167,6 +170,7 @@ private static IMvcCoreBuilder AddControllersCore(IServiceCollection services)
167170
/// To add services for pages call <see cref="AddRazorPages(IServiceCollection)"/>.
168171
/// </para>
169172
/// </remarks>
173+
[RequiresUnreferencedCode("MVC does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
170174
public static IMvcBuilder AddControllersWithViews(this IServiceCollection services)
171175
{
172176
ArgumentNullException.ThrowIfNull(services);
@@ -199,6 +203,7 @@ public static IMvcBuilder AddControllersWithViews(this IServiceCollection servic
199203
/// To add services for pages call <see cref="AddRazorPages(IServiceCollection)"/>.
200204
/// </para>
201205
/// </remarks>
206+
[RequiresUnreferencedCode("MVC does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
202207
public static IMvcBuilder AddControllersWithViews(this IServiceCollection services, Action<MvcOptions>? configure)
203208
{
204209
ArgumentNullException.ThrowIfNull(services);
@@ -246,6 +251,7 @@ private static IMvcCoreBuilder AddControllersWithViewsCore(IServiceCollection se
246251
/// To add services for controllers with views call <see cref="AddControllersWithViews(IServiceCollection)"/>.
247252
/// </para>
248253
/// </remarks>
254+
[RequiresUnreferencedCode("Razor Pages does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
249255
public static IMvcBuilder AddRazorPages(this IServiceCollection services)
250256
{
251257
ArgumentNullException.ThrowIfNull(services);
@@ -276,6 +282,7 @@ public static IMvcBuilder AddRazorPages(this IServiceCollection services)
276282
/// To add services for controllers with views call <see cref="AddControllersWithViews(IServiceCollection)"/>.
277283
/// </para>
278284
/// </remarks>
285+
[RequiresUnreferencedCode("Razor Pages does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
279286
public static IMvcBuilder AddRazorPages(this IServiceCollection services, Action<RazorPagesOptions>? configure)
280287
{
281288
ArgumentNullException.ThrowIfNull(services);

src/Security/Authentication/Core/src/AuthenticationServiceCollectionExtensions.cs

Lines changed: 4 additions & 0 deletions
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 Microsoft.AspNetCore.Authentication;
56
using Microsoft.Extensions.DependencyInjection.Extensions;
67

@@ -16,6 +17,7 @@ public static class AuthenticationServiceCollectionExtensions
1617
/// </summary>
1718
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
1819
/// <returns>A <see cref="AuthenticationBuilder"/> that can be used to further configure authentication.</returns>
20+
[RequiresUnreferencedCode("Authentication middleware does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
1921
public static AuthenticationBuilder AddAuthentication(this IServiceCollection services)
2022
{
2123
ArgumentNullException.ThrowIfNull(services);
@@ -36,6 +38,7 @@ public static AuthenticationBuilder AddAuthentication(this IServiceCollection se
3638
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
3739
/// <param name="defaultScheme">The default scheme used as a fallback for all other schemes.</param>
3840
/// <returns>A <see cref="AuthenticationBuilder"/> that can be used to further configure authentication.</returns>
41+
[RequiresUnreferencedCode("Authentication middleware does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
3942
public static AuthenticationBuilder AddAuthentication(this IServiceCollection services, string defaultScheme)
4043
=> services.AddAuthentication(o => o.DefaultScheme = defaultScheme);
4144

@@ -45,6 +48,7 @@ public static AuthenticationBuilder AddAuthentication(this IServiceCollection se
4548
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
4649
/// <param name="configureOptions">A delegate to configure <see cref="AuthenticationOptions"/>.</param>
4750
/// <returns>A <see cref="AuthenticationBuilder"/> that can be used to further configure authentication.</returns>
51+
[RequiresUnreferencedCode("Authentication middleware does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
4852
public static AuthenticationBuilder AddAuthentication(this IServiceCollection services, Action<AuthenticationOptions> configureOptions)
4953
{
5054
ArgumentNullException.ThrowIfNull(services);

src/SignalR/server/SignalR/src/SignalRDependencyInjectionExtensions.cs

Lines changed: 3 additions & 0 deletions
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 Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.SignalR;
67
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -34,6 +35,7 @@ public static ISignalRServerBuilder AddHubOptions<THub>(this ISignalRServerBuild
3435
/// </summary>
3536
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
3637
/// <returns>An <see cref="ISignalRServerBuilder"/> that can be used to further configure the SignalR services.</returns>
38+
[RequiresUnreferencedCode("SignalR does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
3739
public static ISignalRServerBuilder AddSignalR(this IServiceCollection services)
3840
{
3941
ArgumentNullException.ThrowIfNull(services);
@@ -53,6 +55,7 @@ public static ISignalRServerBuilder AddSignalR(this IServiceCollection services)
5355
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
5456
/// <param name="configure">An <see cref="Action{HubOptions}"/> to configure the provided <see cref="HubOptions"/>.</param>
5557
/// <returns>An <see cref="ISignalRServerBuilder"/> that can be used to further configure the SignalR services.</returns>
58+
[RequiresUnreferencedCode("SignalR does not currently support native AOT.", Url = "https://aka.ms/aspnet/nativeaot")]
5659
public static ISignalRServerBuilder AddSignalR(this IServiceCollection services, Action<HubOptions> configure)
5760
{
5861
ArgumentNullException.ThrowIfNull(services);

0 commit comments

Comments
 (0)