diff --git a/eng/TrimmableProjects.props b/eng/TrimmableProjects.props index 4646bb59dc70..ef28ab2b815d 100644 --- a/eng/TrimmableProjects.props +++ b/eng/TrimmableProjects.props @@ -32,6 +32,7 @@ + diff --git a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj index c723bd1a4d71..8e250fbca642 100644 --- a/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj +++ b/src/Http/Http.Extensions/gen/Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj @@ -27,6 +27,7 @@ + diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs index 70e48a535aa1..22a9bc774439 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Endpoint.cs @@ -163,8 +163,9 @@ public static int GetSignatureHashCode(Endpoint endpoint) private static (string, int) GetLocation(IInvocationOperation operation) { - var filePath = operation.Syntax.SyntaxTree.FilePath; - var span = operation.Syntax.SyntaxTree.GetLineSpan(operation.Syntax.Span); + var operationSpan = operation.Syntax.Span; + var filePath = operation.Syntax.SyntaxTree.GetDisplayPath(operationSpan, operation.SemanticModel?.Compilation.Options.SourceReferenceResolver); + var span = operation.Syntax.SyntaxTree.GetLineSpan(operationSpan); var lineNumber = span.StartLinePosition.Line + 1; return (filePath, lineNumber); } diff --git a/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs b/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs index 45f0724dfcf0..11a40a5e74be 100644 --- a/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs +++ b/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.AspNetCore.Authentication.BearerToken.DTO; using Microsoft.AspNetCore.Builder; @@ -28,8 +27,6 @@ public static class IdentityApiEndpointRouteBuilderExtensions /// Call to add a prefix to all the endpoints. /// /// An to further customize the added endpoints. - // TODO: Remove RequiresDynamicCode when https://github.com/dotnet/aspnetcore/issues/47918 is fixed and RDG is enabled. - [RequiresDynamicCode("This API requires generated code that is not compatible with native AOT applications.")] public static IEndpointConventionBuilder MapIdentityApi(this IEndpointRouteBuilder endpoints) where TUser : class, new() { ArgumentNullException.ThrowIfNull(endpoints); diff --git a/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj b/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj index c86f186db971..3530a7c946e6 100644 --- a/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj +++ b/src/Identity/Core/src/Microsoft.AspNetCore.Identity.csproj @@ -7,8 +7,8 @@ true aspnetcore;identity;membership false - - + true + true @@ -31,7 +31,6 @@ - - + diff --git a/src/Shared/RoslynUtils/SyntaxTreeExtensions.cs b/src/Shared/RoslynUtils/SyntaxTreeExtensions.cs new file mode 100644 index 000000000000..47bd7babd313 --- /dev/null +++ b/src/Shared/RoslynUtils/SyntaxTreeExtensions.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Text; + +internal static class SyntaxTreeExtensions +{ + // Utilize the same logic used by the `CallerLinePathAttribute` for generating + // a file path for a given syntax tree. + // Source copied from https://github.com/dotnet/roslyn/blob/5b47c7fe326faa35940f220c14f718cd0b820c38/src/Compilers/Core/Portable/Syntax/SyntaxTree.cs#L274-L293 until + // public APIs are available. + internal static string GetDisplayPath(this SyntaxTree tree, TextSpan span, SourceReferenceResolver? resolver) + { + var mappedSpan = tree.GetMappedLineSpan(span); + if (resolver == null || mappedSpan.Path.Length == 0) + { + return mappedSpan.Path; + } + + return resolver.NormalizePath(mappedSpan.Path, baseFilePath: mappedSpan.HasMappedPath ? tree.FilePath : null) ?? mappedSpan.Path; + } +}