diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorTemplateEngineFactoryService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorTemplateEngineFactoryService.cs new file mode 100644 index 0000000000..f24dc2f1c6 --- /dev/null +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/DefaultRazorTemplateEngineFactoryService.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.ComponentModel.Composition; +using Microsoft.AspNetCore.Mvc.Razor.Extensions; +using Microsoft.AspNetCore.Razor.Evolution; + +namespace Microsoft.VisualStudio.LanguageServices.Razor +{ + [Export(typeof(RazorTemplateEngineFactoryService))] + internal class DefaultRazorTemplateEngineFactoryService : RazorTemplateEngineFactoryService + { + public override RazorTemplateEngine Create(string projectPath, Action configure) + { + if (projectPath == null) + { + throw new ArgumentNullException(nameof(projectPath)); + } + + var engine = RazorEngine.CreateDesignTime(b => + { + configure?.Invoke(b); + + // For now we're hardcoded to use MVC's extensibility. + RazorExtensions.Register(b); + }); + + var templateEngine = new MvcRazorTemplateEngine(engine, new FileSystemRazorProject(projectPath)); + templateEngine.Options.ImportsFileName = "_ViewImports.cshtml"; + return templateEngine; + } + } +} diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj b/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj index 67a3d5daf5..9f022f5ce2 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj @@ -41,6 +41,7 @@ + diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorTemplateEngineFactoryService.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorTemplateEngineFactoryService.cs new file mode 100644 index 0000000000..68b1a683a6 --- /dev/null +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/RazorTemplateEngineFactoryService.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Razor.Evolution; + +namespace Microsoft.VisualStudio.LanguageServices.Razor +{ + public abstract class RazorTemplateEngineFactoryService + { + public abstract RazorTemplateEngine Create(string projectPath, Action configure); + } +}