IMPORTANT: This tool is highly experimental, and it might break your Rider installation if you don't follow the installation instructions. Only tested with Rider 2022.2, and with smaller projects.
UPDATE: It is confirmed that this issue was fixed internally, and will hopefully ship with Rider 2022.3. I would highly recommend waiting for the update rather than using my fix.
This is a simple bytecode modification to the JetBrains Rider IDE that enables the EditAndContinue feature for .razor
files Blazor Server applications. This means that whenever you edit a Razor file, Rider will display the "Sources are modified" prompt, allowing you to "Apply changes" and hot-reload the project. Note that this only works for Blazor Server applications. Blazor WASM is not supported by this tool. This tool is a partial fix for RIDER-69647.
Actually it can, it just doesn't want to. Everything needed to hot-reload a Blazor Server project is already fully implemented in Rider, with the exception of one small detail. Without going too deep into the inner workings of EnC in Rider, there are a set of java classes that contain the logic that decides whether or not the hot reload notification should be displayed after a file was modified.
In the case of .razor
files, this class is com.jetbrains.rider.ideaInterop.fileTypes.razor.debugger.RazorEncWritingAccessProvider
, more specifically the isSupportedFile
method. By default, this method checks if the modified file's language equals "Razor", and only then does it return true. That's where the problem is. For some reason, the method that gets an open file's language will always return the string "Blazor", which doesn't match, and the isSupportedFile
method returns false. Whether the isSupportedFile
method is checking the wrong value, or the file language is incorrect is something that only JetBrains developers can tell.
This project is basically a Java Agent that modifies the mentioned class before it gets loaded into the java runtime. While loading the class, it replaces the string "Razor" with "Blazor" in the isSupportedFile
method to ensure that the "Apply Changes" button appears after modifying a .razor file.
- Download a prebuilt binary (e.g.
%localappdata%\JetBrains\rider-razor-fix.jar
), or optionally clone this repo and build it yourself. Make sure to use theshadowJar
gradle task to generate the .jar file - Open Rider, go to Help > Edit Custom VM Options
- Add this at the end of the file:
-javaagent:C:\\Users\\Sparky\\AppData\\Local\\JetBrains\\rider-razor-fix.jar
. Make sure you type the exact full path without quotes, and replace all\
characters with\\
. If there are spaces in the file's full path, move it to a different location so there are no spaces. - Restart Rider
If you accidentally misspell something in the VM options file, or delete the downloaded .jar file, Rider won't be able to start anymore. In this case read this or this article to locate your .vmoptions file, and manually fix or remove the javaagent
flag.