-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Milestone
Description
This is the discussion issue for aspnet/Announcements#433
Removed RazorTemplateEngine API
The RazorTemplateEngine
API was removed in favor of RazorProjectEngine
.
Version introduced
3.0
Old behavior
A template engine could be created and used to parse and generate code for Razor files
New behavior
A RazorProjectEngine
can be created and fed the same type of information as a RazorTemplateEngine
to parse and generate code for Razor files. It also provides extra levels of configurability.
Reason for change
RazorTemplateEngine
was too coupled to our existing implementations and ultimately led to more questions when trying to properly configure a Razor parsing/generation pipeline.
Recommended action
Use RazorProjectEngine
instead of RazorTemplateEngine
.
Creating & configuring the RazorProjectEngine
var projectEngine = RazorProjectEngine.Create(
RazorConfiguration.Default,
RazorProjectFileSystem.Create(@"C:/Users/nimullen/source/repos/ConsoleApp4/ConsoleApp4"),
builder =>
{
builder.ConfigureClass((document, classNode) =>
{
classNode.ClassName = "MyClassName";
// Can also configure other aspects of the class here.
});
// More configuration can go here
});
Generating code for a Razor file
var item = projectEngine.FileSystem.GetItem(@"C:\Users\nimullen\source\repos\ConsoleApp4\ConsoleApp4\Example.cshtml", FileKinds.Legacy);
var output = projectEngine.Process(item);
// Things available
var syntaxTree = output.GetSyntaxTree();
var intermediateDocument = output.GetDocumentIntermediateNode();
var csharpDocument = output.GetCSharpDocument();
Category
ASP.NET
Affected APIs
- RazorTemplateEngine
- RazorTemplateEngineOptions
Issue metadata
- Issue type: breaking-change
BartmaxBartmax
Metadata
Metadata
Assignees
Labels
No labels