diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/MvcRazorTemplateEngine.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/MvcRazorTemplateEngine.cs
deleted file mode 100644
index 497d173e4e..0000000000
--- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/src/MvcRazorTemplateEngine.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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.IO;
-using System.Text;
-using Microsoft.AspNetCore.Razor.Language;
-
-namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
-{
- ///
- /// A for Mvc Razor views.
- ///
- public class MvcRazorTemplateEngine : RazorTemplateEngine
- {
- ///
- /// Initializes a new instance of .
- ///
- /// The .
- /// The .
- public MvcRazorTemplateEngine(
- RazorEngine engine,
- RazorProject project)
- : base(engine, project)
- {
- Options.ImportsFileName = "_ViewImports.cshtml";
- Options.DefaultImports = GetDefaultImports();
- }
-
- public override RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
- {
- return base.CreateCodeDocument(projectItem);
- }
-
- // Internal for testing.
- internal static RazorSourceDocument GetDefaultImports()
- {
- using (var stream = new MemoryStream())
- using (var writer = new StreamWriter(stream, Encoding.UTF8))
- {
- writer.WriteLine("@using System");
- writer.WriteLine("@using System.Collections.Generic");
- writer.WriteLine("@using System.Linq");
- writer.WriteLine("@using System.Threading.Tasks");
- writer.WriteLine("@using Microsoft.AspNetCore.Mvc");
- writer.WriteLine("@using Microsoft.AspNetCore.Mvc.Rendering");
- writer.WriteLine("@using Microsoft.AspNetCore.Mvc.ViewFeatures");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider");
- writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor");
- writer.Flush();
-
- stream.Position = 0;
- return RazorSourceDocument.ReadFrom(stream, fileName: null, encoding: Encoding.UTF8);
- }
- }
- }
-}
diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/MvcRazorTemplateEngineTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/MvcRazorTemplateEngineTest.cs
deleted file mode 100644
index eca2b8d49b..0000000000
--- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/MvcRazorTemplateEngineTest.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-// 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.Linq;
-using Microsoft.AspNetCore.Razor.Language;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
-{
- public class MvcRazorTemplateEngineTest : RazorProjectEngineTestBase
- {
- protected override RazorLanguageVersion Version => RazorLanguageVersion.Version_1_1;
-
- [Fact]
- public void GetDefaultImports_IncludesDefaultImports()
- {
- // Arrange
- var expectedImports = new[]
- {
- "@using System",
- "@using System.Collections.Generic",
- "@using System.Linq",
- "@using System.Threading.Tasks",
- "@using Microsoft.AspNetCore.Mvc",
- "@using Microsoft.AspNetCore.Mvc.Rendering",
- "@using Microsoft.AspNetCore.Mvc.ViewFeatures",
- };
- var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
- CreateProjectEngine().Engine,
- new TestRazorProjectFileSystem());
-
- // Act
- var imports = mvcRazorTemplateEngine.Options.DefaultImports;
-
- // Assert
- var importContent = GetContent(imports)
- .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
- .Where(line => line.StartsWith("@using"));
- Assert.Equal(expectedImports, importContent);
- }
-
- [Fact]
- public void GetDefaultImports_IncludesDefaulInjects()
- {
- // Arrange
- var expectedImports = new[]
- {
- "@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html",
- "@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json",
- "@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component",
- "@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url",
- "@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider",
- };
- var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
- CreateProjectEngine().Engine,
- new TestRazorProjectFileSystem());
-
- // Act
- var imports = mvcRazorTemplateEngine.Options.DefaultImports;
-
- // Assert
- var importContent = GetContent(imports)
- .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
- .Where(line => line.StartsWith("@inject"));
- Assert.Equal(expectedImports, importContent);
- }
-
- [Fact]
- public void GetDefaultImports_IncludesDefaultTagHelpers()
- {
- // Arrange
- var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
- CreateProjectEngine().Engine,
- new TestRazorProjectFileSystem());
-
- // Act
- var imports = mvcRazorTemplateEngine.Options.DefaultImports;
-
- // Assert
- var importContent = GetContent(imports)
- .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
- .Where(line => line.StartsWith("@addTagHelper"));
- Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
- }
-
- private string GetContent(RazorSourceDocument imports)
- {
- var contentChars = new char[imports.Length];
- imports.CopyTo(0, contentChars, 0, imports.Length);
- return new string(contentChars);
- }
- }
-}
diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcRazorTemplateEngine.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcRazorTemplateEngine.cs
deleted file mode 100644
index f278b20a45..0000000000
--- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcRazorTemplateEngine.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-// 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.IO;
-using System.Text;
-using Microsoft.AspNetCore.Razor.Language;
-
-namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
-{
- ///
- /// A for Mvc Razor views.
- ///
- public class MvcRazorTemplateEngine : RazorTemplateEngine
- {
- ///
- /// Initializes a new instance of .
- ///
- /// The .
- /// The .
- public MvcRazorTemplateEngine(
- RazorEngine engine,
- RazorProject project)
- : base(engine, project)
- {
- Options.ImportsFileName = "_ViewImports.cshtml";
- Options.DefaultImports = GetDefaultImports();
- }
-
- public override RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
- {
- return base.CreateCodeDocument(projectItem);
- }
-
- // Internal for testing.
- internal static RazorSourceDocument GetDefaultImports()
- {
- using (var stream = new MemoryStream())
- using (var writer = new StreamWriter(stream, Encoding.UTF8))
- {
- writer.WriteLine("@using System");
- writer.WriteLine("@using System.Collections.Generic");
- writer.WriteLine("@using System.Linq");
- writer.WriteLine("@using System.Threading.Tasks");
- writer.WriteLine("@using Microsoft.AspNetCore.Mvc");
- writer.WriteLine("@using Microsoft.AspNetCore.Mvc.Rendering");
- writer.WriteLine("@using Microsoft.AspNetCore.Mvc.ViewFeatures");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url");
- writer.WriteLine("@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider");
- writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor");
- writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor");
- writer.WriteLine("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor");
- writer.Flush();
-
- stream.Position = 0;
- return RazorSourceDocument.ReadFrom(stream, fileName: null, encoding: Encoding.UTF8);
- }
- }
- }
-}
diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcRazorTemplateEngineTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcRazorTemplateEngineTest.cs
deleted file mode 100644
index c5a25d29aa..0000000000
--- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcRazorTemplateEngineTest.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-// 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.Linq;
-using Microsoft.AspNetCore.Razor.Language;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
-{
- public class MvcRazorTemplateEngineTest : RazorProjectEngineTestBase
- {
- protected override RazorLanguageVersion Version => RazorLanguageVersion.Version_3_0;
-
- [Fact]
- public void GetDefaultImports_IncludesDefaultImports()
- {
- // Arrange
- var expectedImports = new[]
- {
- "@using System",
- "@using System.Collections.Generic",
- "@using System.Linq",
- "@using System.Threading.Tasks",
- "@using Microsoft.AspNetCore.Mvc",
- "@using Microsoft.AspNetCore.Mvc.Rendering",
- "@using Microsoft.AspNetCore.Mvc.ViewFeatures",
- };
-
- var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
- CreateProjectEngine().Engine,
- new TestRazorProjectFileSystem());
-
- // Act
- var imports = mvcRazorTemplateEngine.Options.DefaultImports;
-
- // Assert
- var importContent = GetContent(imports)
- .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
- .Where(line => line.StartsWith("@using"));
- Assert.Equal(expectedImports, importContent);
- }
-
- [Fact]
- public void GetDefaultImports_IncludesDefaulInjects()
- {
- // Arrange
- var expectedImports = new[]
- {
- "@inject global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html",
- "@inject global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json",
- "@inject global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component",
- "@inject global::Microsoft.AspNetCore.Mvc.IUrlHelper Url",
- "@inject global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider",
- };
- var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
- CreateProjectEngine().Engine,
- new TestRazorProjectFileSystem());
-
- // Act
- var imports = mvcRazorTemplateEngine.Options.DefaultImports;
-
- // Assert
- var importContent = GetContent(imports)
- .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
- .Where(line => line.StartsWith("@inject"));
- Assert.Equal(expectedImports, importContent);
- }
-
- [Fact]
- public void GetDefaultImports_IncludesDefaultTagHelpers()
- {
- // Arrange
- var mvcRazorTemplateEngine = new MvcRazorTemplateEngine(
- CreateProjectEngine().Engine,
- new TestRazorProjectFileSystem());
-
- // Act
- var imports = mvcRazorTemplateEngine.Options.DefaultImports;
-
- // Assert
- var importContent = GetContent(imports)
- .Split(new[] { Environment.NewLine }, StringSplitOptions.None)
- .Where(line => line.StartsWith("@addTagHelper"));
- Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
- Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
- Assert.Contains("@addTagHelper Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor", importContent);
- }
-
- private string GetContent(RazorSourceDocument imports)
- {
- var contentChars = new char[imports.Length];
- imports.CopyTo(0, contentChars, 0, imports.Length);
- return new string(contentChars);
- }
- }
-}
diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Properties/Resources.Designer.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Properties/Resources.Designer.cs
index c8581e85d8..be43f4d896 100644
--- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Properties/Resources.Designer.cs
+++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Properties/Resources.Designer.cs
@@ -1208,20 +1208,6 @@ namespace Microsoft.AspNetCore.Razor.Language
internal static string FormatRazorProject_PathMustStartWithForwardSlash()
=> GetString("RazorProject_PathMustStartWithForwardSlash");
- ///
- /// The item '{0}' could not be found.
- ///
- internal static string RazorTemplateEngine_ItemCouldNotBeFound
- {
- get => GetString("RazorTemplateEngine_ItemCouldNotBeFound");
- }
-
- ///
- /// The item '{0}' could not be found.
- ///
- internal static string FormatRazorTemplateEngine_ItemCouldNotBeFound(object p0)
- => string.Format(CultureInfo.CurrentCulture, GetString("RazorTemplateEngine_ItemCouldNotBeFound"), p0);
-
///
/// Remove Tag Helpers for use in the current document.
///
diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorTemplateEngine.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorTemplateEngine.cs
deleted file mode 100644
index 298666b56f..0000000000
--- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorTemplateEngine.cs
+++ /dev/null
@@ -1,241 +0,0 @@
-// 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.Collections.Generic;
-using System.Linq;
-
-namespace Microsoft.AspNetCore.Razor.Language
-{
- ///
- /// Entry point to parse Razor files and generate code.
- ///
- public class RazorTemplateEngine
- {
- private RazorTemplateEngineOptions _options;
-
- ///
- /// Initializes a new instance of .
- ///
- /// The .
- /// The .
- public RazorTemplateEngine(
- RazorEngine engine,
- RazorProject project)
- {
- if (engine == null)
- {
- throw new ArgumentNullException(nameof(engine));
- }
-
- if (project == null)
- {
- throw new ArgumentNullException(nameof(project));
- }
-
- Engine = engine;
- Project = project;
- _options = new RazorTemplateEngineOptions();
- }
-
- ///
- /// Gets the .
- ///
- public RazorEngine Engine { get; }
-
- ///
- /// Gets the .
- ///
- public RazorProject Project { get; }
-
- ///
- /// Options to configure .
- ///
- public RazorTemplateEngineOptions Options
- {
- get
- {
- return _options;
- }
- set
- {
- _options = value ?? throw new ArgumentNullException(nameof(value));
- }
- }
-
- ///
- /// Parses the template specified by the project item .
- ///
- /// The template path.
- /// The .
- public RazorCSharpDocument GenerateCode(string path)
- {
- if (string.IsNullOrEmpty(path))
- {
- throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
- }
-
- var projectItem = Project.GetItem(path);
- return GenerateCode(projectItem);
- }
-
- ///
- /// Parses the template specified by .
- ///
- /// The .
- /// The .
- public RazorCSharpDocument GenerateCode(RazorProjectItem projectItem)
- {
- if (projectItem == null)
- {
- throw new ArgumentNullException(nameof(projectItem));
- }
-
- if (!projectItem.Exists)
- {
- throw new InvalidOperationException(Resources.FormatRazorTemplateEngine_ItemCouldNotBeFound(projectItem.FilePath));
- }
-
- var codeDocument = CreateCodeDocument(projectItem);
- return GenerateCode(codeDocument);
- }
-
- ///
- /// Parses the template specified by .
- ///
- /// The .
- /// The .
- public virtual RazorCSharpDocument GenerateCode(RazorCodeDocument codeDocument)
- {
- if (codeDocument == null)
- {
- throw new ArgumentNullException(nameof(codeDocument));
- }
-
- Engine.Process(codeDocument);
- return codeDocument.GetCSharpDocument();
- }
-
- ///
- /// Generates a for the specified .
- ///
- /// The template path.
- /// The created .
- public virtual RazorCodeDocument CreateCodeDocument(string path)
- {
- if (string.IsNullOrEmpty(path))
- {
- throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
- }
-
- var projectItem = Project.GetItem(path);
- return CreateCodeDocument(projectItem);
- }
-
- ///
- /// Generates a for the specified .
- ///
- /// The .
- /// The created .
- public virtual RazorCodeDocument CreateCodeDocument(RazorProjectItem projectItem)
- {
- if (projectItem == null)
- {
- throw new ArgumentNullException(nameof(projectItem));
- }
-
- if (!projectItem.Exists)
- {
- throw new InvalidOperationException(Resources.FormatRazorTemplateEngine_ItemCouldNotBeFound(projectItem.FilePath));
- }
-
- var source = RazorSourceDocument.ReadFrom(projectItem);
- var imports = GetImports(projectItem);
-
- return RazorCodeDocument.Create(source, imports);
- }
-
- ///
- /// Gets that are applicable to the specified .
- ///
- /// The template path.
- /// The sequence of applicable .
- public IEnumerable GetImports(string path)
- {
- if (string.IsNullOrEmpty(path))
- {
- throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
- }
-
- var projectItem = Project.GetItem(path);
- return GetImports(projectItem);
- }
-
- ///
- /// Gets that are applicable to the specified .
- ///
- /// The .
- /// The sequence of applicable .
- public virtual IEnumerable GetImports(RazorProjectItem projectItem)
- {
- if (projectItem == null)
- {
- throw new ArgumentNullException(nameof(projectItem));
- }
- var result = new List();
-
- var importProjectItems = GetImportItems(projectItem);
- foreach (var importItem in importProjectItems)
- {
- if (importItem.Exists)
- {
- // We want items in descending order. FindHierarchicalItems returns items in ascending order.
- result.Insert(0, RazorSourceDocument.ReadFrom(importItem));
- }
- }
-
- if (Options.DefaultImports != null)
- {
- result.Insert(0, Options.DefaultImports);
- }
-
- return result;
- }
-
- ///
- /// Gets the sequence of imports with the name specified by
- /// that apply to .
- ///
- /// The path to look up import items for.
- /// A sequence of instances that apply to the
- /// .
- public IEnumerable GetImportItems(string path)
- {
- if (string.IsNullOrEmpty(path))
- {
- throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
- }
-
- var projectItem = Project.GetItem(path);
- return GetImportItems(projectItem);
- }
-
- ///
- /// Gets the sequence of imports with the name specified by
- /// that apply to .
- ///
- /// The to look up import items for.
- /// A sequence of instances that apply to the
- /// .
- public virtual IEnumerable GetImportItems(RazorProjectItem projectItem)
- {
- var importsFileName = Options.ImportsFileName;
- if (!string.IsNullOrEmpty(importsFileName))
- {
- return Project.FindHierarchicalItems(projectItem.FilePath, importsFileName);
- }
-
- return Enumerable.Empty();
- }
- }
-}
diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorTemplateEngineOptions.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorTemplateEngineOptions.cs
deleted file mode 100644
index 4b46eabbc8..0000000000
--- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorTemplateEngineOptions.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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.
-
-namespace Microsoft.AspNetCore.Razor.Language
-{
- ///
- /// Options for code generation in the .
- ///
- public sealed class RazorTemplateEngineOptions
- {
- ///
- /// Gets or sets the file name of the imports file (e.g. _ViewImports.cshtml).
- ///
- public string ImportsFileName { get; set; }
-
- ///
- /// Gets or sets the default set of imports.
- ///
- public RazorSourceDocument DefaultImports { get; set; }
- }
-}
diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Resources.resx b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Resources.resx
index bf15e72279..d7f21d9466 100644
--- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Resources.resx
+++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Resources.resx
@@ -392,9 +392,6 @@ Instead, wrap the contents of the block in "{{}}":
Path must begin with a forward slash '/'.
-
- The item '{0}' could not be found.
-
Remove Tag Helpers for use in the current document.