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?

Guilherme
  • 5,143
  • 5
  • 39
  • 60
  • 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. – Chris Pratt Apr 04 '19 at 16:51
  • Found it: https://github.com/aspnet/AspNetCore/issues/8071 – Guilherme Apr 04 '19 at 16:59
  • 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. – Chris Pratt Apr 04 '19 at 17:08
  • @ChrisPratt exactly. However, the main problem for me is loosing the application state. But this is better than nothing, I guess.. – Guilherme Apr 04 '19 at 17:30
  • 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 stuff – Guilherme Apr 04 '19 at 17:32
  • 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. – Chris Pratt Apr 04 '19 at 17:36

0 Answers0