toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.53k stars 258 forks source link

Debugging capabilities #338

Closed macsux closed 4 years ago

macsux commented 4 years ago

Is there a way to debug Razor template when using this library?

jzabroski commented 4 years ago

I don't debug them. As explained in other places, I avoid business logic in the views and just test my viewmodels. I don't use things like local functions. If you want to write tests, look into SharpPuppeteer for fluent async/await headless browser automation and Verify/ApprovalTests.Net for approval testing.

You might be able to use dnSpy, but without a lack of source maps, the general experience is going to suck. I looked at what Blazor does and they explicitly state they don't support source maps.

Also note that any RazorLight template is in theory a valid ASP.NET Core template - so you can always use ASP.NET Core debugger, but I have never tried that.

One piece of advice I can give is to segregate your javascrit dependencies from your RazorLight logic. Here is an example: https://github.com/damienbod/AspNetCoreInjectConfigurationRazor - and use Premailer.net for inlining CSS into style attributes. The pragmatism behind this advice is that it minimizes figuring out what could cause a regression.