I have a plugin architecture where I use the app.MapRazorComponents<MyApp>().AddAdditionalAssemblies()
method to add the plugin assemblies to Razor page mapping.
The plugins are not guaranteed to include any pages so I only want to add assemblies that has files with the @page
directive.
I’ve done some debugging to find that the classes generated for the .razor
files have the [Microsoft.AspNetCore.Components.RouteAttribute]
set on them, so I guess the @page
directive is translated to a [Route]
attribute.
The [Route]
attribute, however, can also be used on Controllers, which are added differently (.MapControllers()
), so only using this attribute as a marker is not enough.
I could probably exclude types that also has the [ApiController]
attribute, or add checks for even more attributes (or inheritances), but I feel this can quickly get out of hand.
Is there a way to check if an assembly contains any .razor
files (be it pages or components), or alternatively check if an assembly is a “Razor Class Library” or not just a “Class Library”?