Razor runtime recompilation does not seems to work with *.razor component files
Asked Answered
R

0

6

I'm testing the new Razor Components (aka. Server Side Blazor) and I'm finding the need to stop the project, edit, recompile and restart the server, very time consuming. I want to edit the *.razor files, save, press F5 on the browser, and done.

I know there is a breaking change on ASP.NET Core 3, that prevented this from happening for a while. But now, there is a "fix": you just need to install the package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation, and setup the service like that:

services.AddMvc()
.AddRazorRuntimeCompilation();

(Yes, without Mvc, see this)

But that does not seems to work - at least, I did not try with cshtml files, since I am only using *.razor in my tests.

I also did:

services.AddMvc()
.AddRazorRuntimeCompilation((options) =>
{
    foreach (var item in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.razor", SearchOption.AllDirectories))
    {
        options.AdditionalReferencePaths.Add(item);
    }
});

Without any luck.

Is this not yet supported or I am doing something wrong?

Repp answered 4/4, 2019 at 16:14 Comment(6)
I don't think this actually applies to Razor components. It's talking about view compilation. Razor components are actually rendered into an in-memory DOM representation, which by the sound of it, seems like it would be tricky to alter every time you make a change in a *.razor file. Rebuilding has the effect of dump the in-memory tree, so it is then recreated (thus applying your update). You might be better served by actually asking this question in a issue on the Github project page.Gleaning
Found it: github.com/aspnet/AspNetCore/issues/8071Repp
Hey. What do you know. My guess was pretty much correct. Although, the bit about dotnet watch, I hadn't considered. That should work for you. You still have to rebuild, but that will effectively automatically kick off the build for you.Gleaning
@ChrisPratt exactly. However, the main problem for me is loosing the application state. But this is better than nothing, I guess..Repp
Razor Components does not seem to be "stateless", and I guess that if I manage to maintain the Browser open (trying to maintain the state) between builds, it will break stuffRepp
Yes. It's definitely not stateless. Essentially, it's creating a server-side approximation of the client-side DOM. Obviously, for that to work, the two need to be in sync. If the it loses the state server-side, then nothing is right.Gleaning

© 2022 - 2024 — McMap. All rights reserved.