DamianEdwards / RazorSlices

Lightweight Razor-based templates for ASP.NET Core without MVC, Razor Pages, or Blazor.
MIT License
343 stars 16 forks source link

How do I use the "Razor Slices source generator"? #58

Open LAC-Tech opened 3 months ago

LAC-Tech commented 3 months ago

Hello, I have a question from the docs:

Each .cshtml file will have a proxy type generated for it by the Razor Slices source generator that you can use as the generic argument to the various APIs in Razor Slices for rendering slices.

I assume I have to invoke this source generator somehow?

DamianEdwards commented 3 weeks ago

No, source generators are automatically invoked by the compiler. As long as you're in a supporting environment, e.g. Visual Studio, VS Code with C# Dev Kit, etc., and you reference the RazorSlices package and have some .cshtml files in your project, you should see the generated types become available in your IntelliSense/statement-completion, e.g. the below image is in Visual Studio:

image

And in VS Code with C# Dev Kit:

image   Note that it can take a few seconds for it all to initialize before the generated types show up.