From 307fcce97aae4ce83ee5374312d1de976e2ba75d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 25 Sep 2025 09:48:14 +0000 Subject: [PATCH 1/2] Initial plan From f466f99bd6e738fb65688238815e357a276a1e5b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 25 Sep 2025 10:05:06 +0000 Subject: [PATCH 2/2] Add RazorComponentCodeBehind item template with tests Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com> --- .../.template.config/dotnetcli.host.json | 3 ++ .../localize/templatestrings.cs.json | 7 +++ .../localize/templatestrings.de.json | 7 +++ .../localize/templatestrings.en.json | 7 +++ .../localize/templatestrings.es.json | 7 +++ .../localize/templatestrings.fr.json | 7 +++ .../localize/templatestrings.it.json | 7 +++ .../localize/templatestrings.ja.json | 7 +++ .../localize/templatestrings.ko.json | 7 +++ .../localize/templatestrings.pl.json | 7 +++ .../localize/templatestrings.pt-BR.json | 7 +++ .../localize/templatestrings.ru.json | 7 +++ .../localize/templatestrings.tr.json | 7 +++ .../localize/templatestrings.zh-Hans.json | 7 +++ .../localize/templatestrings.zh-Hant.json | 7 +++ .../.template.config/template.json | 53 +++++++++++++++++++ .../RazorComponentCodeBehind/Component1.razor | 5 ++ .../Component1.razor.cs | 9 ++++ .../ItemTemplateTests/BlazorServerTests.cs | 18 +++++++ 19 files changed, 186 insertions(+) create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/dotnetcli.host.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.cs.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.de.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.en.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.es.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.fr.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.it.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ja.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ko.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pl.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pt-BR.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ru.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.tr.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hans.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hant.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/template.json create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor create mode 100644 src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor.cs diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/dotnetcli.host.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/dotnetcli.host.json new file mode 100644 index 000000000000..dfdc5962202e --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/dotnetcli.host.json @@ -0,0 +1,3 @@ +{ + "$schema": "https://json.schemastore.org/dotnetcli.host" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.cs.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.cs.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.cs.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.de.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.de.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.de.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.en.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.en.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.en.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.es.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.es.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.es.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.fr.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.fr.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.fr.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.it.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.it.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.it.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ja.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ja.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ja.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ko.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ko.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ko.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pl.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pl.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pl.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pt-BR.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pt-BR.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.pt-BR.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ru.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ru.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.ru.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.tr.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.tr.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.tr.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hans.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hans.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hans.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hant.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hant.json new file mode 100644 index 000000000000..7e4c6ebbda72 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/localize/templatestrings.zh-Hant.json @@ -0,0 +1,7 @@ +{ + "author": "Microsoft", + "name": "Razor Component with Code-Behind", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "symbols/namespace/description": "namespace for the generated code", + "postActions/openInEditor/description": "Opens Component1.razor in the editor" +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/template.json b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/template.json new file mode 100644 index 000000000000..74224d12e87d --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/.template.config/template.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://json.schemastore.org/template", + "author": "Microsoft", + "classifications": [ + "Web", + "ASP.NET" + ], + "name": "Razor Component with Code-Behind", + "generatorVersions": "[1.0.0.0-*)", + "description": "A reusable UI component implemented with Razor and a code-behind file", + "tags": { + "language": "C#", + "type": "item" + }, + "groupIdentity": "Microsoft.AspNetCore.Components.RazorComponentCodeBehind", + "precedence": "10000", + "identity": "Microsoft.AspNetCore.Components.RazorComponentCodeBehind.10.0", + "shortname": "razorcomponent-cb", + "sourceName": "Component1", + "primaryOutputs": [ + { + "path": "Component1.razor" + }, + { + "path": "Component1.razor.cs" + } + ], + "defaultName": "Component1", + "symbols": { + "namespace": { + "description": "namespace for the generated code", + "replaces": "MyApp.Namespace", + "type": "parameter" + }, + "HostIdentifier": { + "type": "bind", + "binding": "HostIdentifier" + } + }, + "postActions": [ + { + "id": "openInEditor", + "condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")", + "description": "Opens Component1.razor in the editor", + "manualInstructions": [], + "actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6", + "args": { + "files": "0" + }, + "continueOnError": true + } + ] +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor new file mode 100644 index 000000000000..9c2687c6a65b --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor @@ -0,0 +1,5 @@ +

Component1

+ +@code { + +} \ No newline at end of file diff --git a/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor.cs b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor.cs new file mode 100644 index 000000000000..a775a259a912 --- /dev/null +++ b/src/ProjectTemplates/Web.ItemTemplates/content/RazorComponentCodeBehind/Component1.razor.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Components; + +namespace MyApp.Namespace +{ + public partial class Component1 : ComponentBase + { + + } +} \ No newline at end of file diff --git a/src/ProjectTemplates/test/Templates.Tests/ItemTemplateTests/BlazorServerTests.cs b/src/ProjectTemplates/test/Templates.Tests/ItemTemplateTests/BlazorServerTests.cs index c50e7e7f9a5a..b1576693d3bb 100644 --- a/src/ProjectTemplates/test/Templates.Tests/ItemTemplateTests/BlazorServerTests.cs +++ b/src/ProjectTemplates/test/Templates.Tests/ItemTemplateTests/BlazorServerTests.cs @@ -34,4 +34,22 @@ public async Task BlazorServerItemTemplate() Project.AssertFileExists("Different.razor", shouldExist: true); Assert.Contains("

Different

", Project.ReadFile("Different.razor")); } + + [Fact] + public async Task BlazorServerItemTemplateCodeBehind() + { + Project = await ProjectFactory.CreateProject(Output); + + await Project.RunDotNetNewAsync("razorcomponent-cb --name CodeBehindComponent", isItemTemplate: true); + + Project.AssertFileExists("CodeBehindComponent.razor", shouldExist: true); + Project.AssertFileExists("CodeBehindComponent.razor.cs", shouldExist: true); + + var razorContent = Project.ReadFile("CodeBehindComponent.razor"); + var codeContent = Project.ReadFile("CodeBehindComponent.razor.cs"); + + Assert.Contains("

CodeBehindComponent

", razorContent); + Assert.Contains("public partial class CodeBehindComponent : ComponentBase", codeContent); + Assert.Contains("using Microsoft.AspNetCore.Components;", codeContent); + } }