dotnet/roslyn

RegexGenerator does not work in Razor files

Closed this issue · 6 comments

Version Used: 17.2-Preview1

Steps to Reproduce:

  1. Create a Blazor project
  2. Open Index.Razor
  3. Replace its content with
@using System.Text.RegularExpressions

@code {
    [RegexGenerator("[0-9]")] private static partial Regex someRegex();
}
  1. Build the project

Expected Behavior:
No compile error

Actual Behavior:
Compile error:
image

Additional Notes:
I'm assuming this is due to SourceGenerators not being able to reliable consume outputs from other SourceGenerators

cc @timheuer for info

jcouv commented

I think this is by design (no ordering or dependencies between source generators). Tagging @chsienki to confirm.

From a user experience standpoint, the developer doesn't know this, they are following tutorials and blog posts and writing C#...which they can do in code blocks. Ideally the C# developer shouldn't know this, but if this is going to be an unsupported language+tools feature, is there some type of analyzer we could have to indicate this won't be supported?

related to: #57239

it's again one of those "i made my decl so much larger for what is information that i effectively want to be extremely minor".

Sure, but i'm not sure how this is different from any situation with generators. Any time someone is using generator A, and then they add generator B, they have to understand (and/or accept) that generator A and B cannot play together.

but if this is going to be an unsupported language+tools feature, is there some type of analyzer we could have to indicate this won't be supported?

That does seem reasonable. Perhaps we should advise generators to also ship with a corresponding analyzer that then checks any SG docs created in the final compilation. If they detect their trigger case in that generated doc, they can warn.

jcouv commented

Closing this issue as duplicate of #57239. Added a note there to mention the motivating scenario.