From fc7fa2d7eb8df9fb2402868ebdc1e31230ff9f01 Mon Sep 17 00:00:00 2001 From: Christopher Yeleighton Date: Thu, 13 Jan 2022 22:57:54 +0100 Subject: [PATCH] RunTemplateAsync: generate template class name Use the same template class name as `{ dotnet build; }` does. --- .../VS.Web.CG.Templating/RazorTemplating.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Scaffolding/VS.Web.CG.Templating/RazorTemplating.cs b/src/Scaffolding/VS.Web.CG.Templating/RazorTemplating.cs index 8574e76f1..221d7af79 100644 --- a/src/Scaffolding/VS.Web.CG.Templating/RazorTemplating.cs +++ b/src/Scaffolding/VS.Web.CG.Templating/RazorTemplating.cs @@ -12,6 +12,9 @@ using Microsoft.CodeAnalysis.Razor; using Microsoft.VisualStudio.Web.CodeGeneration.Templating.Compilation; +// ClassDeclarationIntermediateNode +using Microsoft.AspNetCore.Razor.Language.Intermediate; + namespace Microsoft.VisualStudio.Web.CodeGeneration.Templating { //Todo: Make this internal and expose as a sevice @@ -41,10 +44,15 @@ public async Task RunTemplateAsync(string content, SectionDirective.Register(builder); - builder.AddTargetExtension(new TemplateTargetExtension() + builder + .AddTargetExtension(new TemplateTargetExtension() { TemplateTypeName = "global::Microsoft.AspNetCore.Mvc.Razor.HelperResult", - }); + }) + .ConfigureClass( + (RazorCodeDocument doc, ClassDeclarationIntermediateNode cl) + => cl.ClassName = string.Join('_', + fileSystem.GetItem(doc.Source.FilePath).FilePathWithoutExtension.Substring(0X1).Split('/')); builder.AddDefaultImports(@" @using System