RazorSlices icon indicating copy to clipboard operation
RazorSlices copied to clipboard

Hot Reload slices while running

Open naasking opened this issue 1 year ago • 2 comments

Hot reload doesn't seem to work for me in VS 2022 version 17.13.0 but supposedly should. I'm running on .NET 9. If I make a small change to this template to remove "Foo!" from the heading:

Image

The "Foo!" from the heading on the web browser still shows up after hot reload and refreshing the page. It does detect a change and the hot reload logs do show that it looks like it's trying to apply changes, but nothing changes. Here are the logs:

11:03 55.74 Site (Web server): Hot reload session started
11:04 36.23 Site (Web server): Sending updates to running application
11:04 36.30 Code changes were successfully applied.
11:04 36.84 Site (Web server): Updates applied successfully
11:04 36.84 Site: Refreshing web browser

I've tried it both with and without a debugger attached. The console doesn't show anything unusual. I created a test project showing this behaviour:

https://github.com/naasking/TestRS

naasking avatar Feb 14 '25 16:02 naasking

OK I think I found the issue. This line in the HotReloadService is not returning true unless the startup hooks flag is explicitly set: https://github.com/DamianEdwards/RazorSlices/blob/cf2e413551e49c3a3b40623ce020d678697f123a/src/RazorSlices/HotReloadService.cs#L17

I think this is a misunderstanding on my part of how this appcontext switch works. I'll do some digging to figure out how to do this check properly. In the meantime you can make it work in your project by adding the following to your .csproj file:

<PropertyGroup>
  <StartupHookSupport Condition="'$(Configuration)' == 'Debug'">true</StartupHookSupport>
</PropertyGroup>

DamianEdwards avatar Feb 14 '25 18:02 DamianEdwards

That works, thanks!

naasking avatar Feb 18 '25 15:02 naasking