Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.NET6] Referencing Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation breaks hot reload for .cshtml files #38965

Closed
BrightSoul opened this issue Dec 11, 2021 · 4 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. Status: Resolved

Comments

@BrightSoul
Copy link

BrightSoul commented Dec 11, 2021

Similar to issue #38809 but this is about regular Razor views, not Blazor components.

Here's the repro steps.

  • Create a new project with dotnet new mvc
  • Reference the razor view runtime compilation package with dotnet add package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
  • Issue: hot reload is no longer watching changes done to .cshtml files. Verify it by running dotnet watch --list. All .cshtml files are no longer listed in the output. Here's a sample output.
> dotnet watch --list
E:\myproject\Controllers\HomeController.cs
E:\myproject\Models\ErrorViewModel.cs
E:\myproject\Program.cs
E:\myproject\MyProject.csproj
E:\myproject\Views\Shared\_Layout.cshtml.css <-- All .cshtml files from /Views are missing
E:\myproject\wwwroot\css\site.css
E:\myproject\wwwroot\favicon.ico
...

I would happily do without the Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package if OmniSharp issue #4822: integrate debugging with dotnet watch was solved. I'm a VSCode user and I would like to use dotnet watch all the time for development but I can't because the debugger won't attach automatically when the process is restarted.

@pranavkm
Copy link
Contributor

RuntimeCompilation and hot reload for cshtml are effectively trying to solve the same problem. As a result, dotnet-watch opts out of watching .cshtml files if the runtime compilation package is reference. That said, you should be able to hit refresh in the browser and see changes to your cshtml files as it has worked in earlier versions of .NET.

@pranavkm pranavkm added ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Dec 11, 2021
@ghost ghost added the Status: Resolved label Dec 11, 2021
@BrightSoul
Copy link
Author

BrightSoul commented Dec 12, 2021

RuntimeCompilation and hot reload for cshtml are effectively trying to solve the same problem

Hot reload is also responsible for refreshing the browser page and that stops happening when the RuntimeCompilation package is referenced. That's the issue.
Instead, it should keep refreshing the page even if the compilation step is performed by the RuntimeCompilation package.

It's underwhelming to hear this is "by design" since there's still no complete solution.

  • With hot reload, we don't get the debugger automatically attached;
  • With the RuntimeCompilation package, the browser page won't reload automatically.
  • They can't be used together.

@ghost
Copy link

ghost commented Dec 13, 2021

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Dec 13, 2021
@dotnetshadow
Copy link

dotnetshadow commented Dec 19, 2021

One possible workaround is to do this:

<ItemGroup>
	  <!-- extends watching group to include *.cshtml files -->
	  <Watch Include="**\*.cshtml" Exclude="node_modules\**\*;**\*.js.map;obj\**\*;bin\**\*" />
  </ItemGroup>

What is the impact of doing this?
Is RuntimeCompilation necessary? I'm converting from .net 5 to .net 6 so I'm wondering how the compilation works now?

I created an issue here, because I didn't see this ticket before
#39111

@ghost ghost locked as resolved and limited conversation to collaborators Jan 18, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants