Description
Today, we need to scan all referenced assemblies to determine whether each assembly has defined any tag helpers. This is pretty inefficient, and pretty wasteful: most assemblies users reference couldn't have defined any tag helpers, since they don't reference Microsoft.AspNetCore.Razor.dll
. Further, even among the assemblies that could have, many won't, so we're wasting a large amount of time looking for tag helpers where none exist. To address this, I'd like to propose the following scanning algorithm for .NET 9:
- Does the assembly reference
Microsoft.AspNetCore.Razor.dll
?- If it does, is the version >8? If so, look for an attribute on the module, something like
Microsoft.AspNetCore.Razor.ContainsTagHelpers
. If that attribute is present, the assembly contains tag helpers and should be searched. Otherwise, it does not contain tag helpers and can be skipped. - If it does, and the version is <=8, scan the assembly. We have no information on whether tag helpers are actually present.
- If it does, is the version >8? If so, look for an attribute on the module, something like
- If it does not, there cannot be any tag helpers. Don't scan the assembly.
This will require putting a new source generator into the ref packages for Microsoft.AspNetCore.Razor
so that anyone that defines tag helpers will get a module attribute automatically. This pattern is inspired by how C# does extension method lookups.
Activity