Source generator for a razor component not working

Viewed 440

I tested the new source generators https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/. My idea was to generate some blazor components, but when I run it, it always adds the .cs extension.

context.AddSource("Test.razor", "Some html");

In the build output I see compile errors coming from Test.razor.cs. Is there a specific reason why it is bound to only cs files and why this cannot work?

1 Answers

Currently source generators only support outputting C# or VB, i.e. source the compiler is building. We're currently working on some support for other things but even then generating a Razor file wouldn't work, simply because by the time your generator is running, the component that processes Razor files has already ran. So there's a complicated chicken-and-egg problem here.

Related