question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider adding an option to the MVC \ Razor Pages template that enables runtime compilation by default

See original GitHub issue

As part of .NET Core 3.0, runtime compilation of views and Razor Pages was moved to a separate package. Our migration guide has a section that deals with re-adding runtime compilation to their projects. Reloading views on file changes relies on VS which only works when the debugger is not attached,

We’ve had several reports of users being surprised or confused when changes to the views aren’t being picked up. This is understandable given users are accustomed to entering <kbd>F5</kbd> in their IDEs and expect things to just work.

One possible way to make this a bit nicer is to have a switch during project creation that enables runtime compilation.

A couple of things to note:

  • The feature requires templating changes with no runtime changes.
  • We would need to surface this experience as a UI gesture (a checkbox) during the VS project creation dialog.
  • We do not want runtime compilation on in non-development environments (runtime compilation results in using the file watcher + blocking async calls both of which are problematic). Having the package reference also results in additional reference assemblies being produced in the build and publish output which we worked hard to eliminate in the 3.0 release. Could we do something more in the templates than adding it behind the IsDevelopment flag to minimize the impact on published apps?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pranavkmcommented, Feb 24, 2020

Verified. For users starting with a new application, both the CLI and VS offer an option to enable runtime compilation. For users updating, here are the two steps required to enable runtime compilation only during development:

a) Add a PackageReference to Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation version 3.1.3 or newer. b) Update launchSettings.json to include a ASPNETCORE_HOSTINGSTARTUPASSEMBLIES environment variables:

"WebApplication3": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
-        "ASPNETCORE_ENVIRONMENT": "Development"
+        "ASPNETCORE_ENVIRONMENT": "Development",
+        "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
      }
    }
0reactions
pranavkmcommented, Feb 18, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Razor file compilation in ASP.NET Core
Build-time and publish-time compilation of Razor files is enabled by default by the Razor SDK. When enabled, runtime compilation complements ...
Read more >
Adding AddRazorRuntimeCompilation() to the container in ...
I was struggling the same problem as well, while trying the versions of Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation nuget package and ...
Read more >
Enable Razor Runtime Compilation
This article/tutorial will show you how to enable runtime compilation when creating ASP.NET Core and ASP.NET Core MVC projects.
Read more >
Razor file compilation in ASP.NET Core
The Razor Pages and MVC project templates include an option to enable runtime compilation when the project is created. This option is supported...
Read more >
Add Razor runtime compilation when developing ASP.NET Core
Runtime compilation of Razor files just worked out of the box with ASP.NET MVC. In this post, I'll show you how we solved...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found