diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs index 740fba6f9a..8e24fd8308 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/MvcServiceProvider.cs @@ -37,14 +37,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal var mvcBuilderConfiguration = GetConfigureCompilationAction(configureCompilationType); var serviceProvider = GetProvider(mvcBuilderConfiguration); - CompilationService = (RazorCompilationService)serviceProvider.GetRequiredService(); Engine = serviceProvider.GetRequiredService(); + TemplateEngine = new MvcRazorTemplateEngine(Engine, serviceProvider.GetRequiredService()) + { + Options = + { + ImportsFileName = "_ViewImports.cshtml", + } + }; Compiler = serviceProvider.GetRequiredService(); ViewEngineOptions = serviceProvider.GetRequiredService>().Value; } - - public RazorCompilationService CompilationService { get; } + public MvcRazorTemplateEngine TemplateEngine { get; } public RazorEngine Engine { get; } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs index 394417eae8..e21de3786b 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs @@ -238,9 +238,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal var fileInfo = files[i]; using (var fileStream = fileInfo.CreateReadStream()) { - var codeDocument = MvcServiceProvider.CompilationService.CreateCodeDocument(fileInfo.ViewEnginePath, fileStream); - var result = MvcServiceProvider.CompilationService.ProcessCodeDocument(codeDocument); - results[i] = new ViewCompilationInfo(fileInfo, result); + var csharpDocument = MvcServiceProvider.TemplateEngine.GenerateCode(fileInfo.ViewEnginePath); + results[i] = new ViewCompilationInfo(fileInfo, csharpDocument); } });