dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.9k stars 4.01k forks source link

Interceptors still require `InterceptorsPreviewNamespaces` property #74511

Closed captainsafia closed 2 weeks ago

captainsafia commented 1 month ago

The compiler will emit a warning for source generators that use interceptors about the need for an InterceptorsPreviewNamespaces property in the target project.

/Users/captainsafia/git/aspnetcore/openapi-fixes/artifacts/obj/Microsoft.AspNetCore.OpenApi/Debug/net9.0/Microsoft.AspNetCore.Http.RequestDelegateGenerator/Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator/GeneratedRouteBuilderExtensions.g.cs(61,10): error CS9137: The 'interceptors' experimental feature is not enabled in this namespace. Add '<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>' to your project.

cc: @jaredpar @RikkiGibson

RikkiGibson commented 1 month ago

My expectation here is that we would introduce an InterceptorsNamespaces property which is basically just an alias for InterceptorsPreviewNamespaces, at least in the medium term.

The reason is that this simplifies "discovery" of [InterceptsLocation] attributes which has to occur when public APIs like SemanticModel.GetInterceptorMethod(InvocationExpressionSyntax) are used.

Essentially until we make the engineering investment to make discovery more performant for editor scenarios it feels like we should continue to require this.