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

Fix hot reload issue. #16624

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,24 @@ public override void ConfigureServices(IServiceCollection services)
services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<RazorViewEngineOptions>, ModularRazorViewEngineOptionsSetup>());

// Support razor runtime compilation only if in dev mode and if the 'refs' folder exists.
var refsFolderExists = Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "refs"));
if (_hostingEnvironment.IsDevelopment())
{
// Support razor runtime compilation only if in dev mode and if the 'refs' folder exists.
var refsFolderExists = Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "refs"));

if (_hostingEnvironment.IsDevelopment() && refsFolderExists)
if (refsFolderExists)
{
builder.AddRazorRuntimeCompilation();
}
}
else
{
builder.AddRazorRuntimeCompilation();
// Share across tenants a static compiler even if there is no runtime compilation
// because the compiler still uses its internal cache to retrieve compiled items.
// Register this provider only in production mode, as it may cause hot reload to fail in development mode.
services.AddSingleton<IViewCompilerProvider, SharedViewCompilerProvider>();
}

// Share across tenants a static compiler even if there is no runtime compilation
// because the compiler still uses its internal cache to retrieve compiled items.
services.AddSingleton<IViewCompilerProvider, SharedViewCompilerProvider>();

services.TryAddEnumerable(
ServiceDescriptor.Transient<IConfigureOptions<MvcRazorRuntimeCompilationOptions>, RazorCompilationOptionsSetup>());

Expand Down