Add RazorComponent with Code-Behind item template #63813
Draft
+186
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses a customer request from VS Feedback to provide an option for creating Razor Component item templates that automatically generate a code-behind (.cs) file alongside the .razor file.
Changes Made
New Item Template:
razorcomponent-cb
razorcomponent-cb
Component1.razor
andComponent1.razor.cs
dotnet new razorcomponent-cb --name MyComponent --namespace MyApp.Components
Template Structure
The new template follows the established code-behind pattern used by Razor Pages:
Component1.razor:
Component1.razor.cs:
Key Features
--namespace
parameter correctly sets the namespace in the code-behind file--name
parameterTesting
BlazorServerItemTemplateCodeBehind
test to validate the new template functionalityrazorcomponent
and newrazorcomponent-cb
templates work independentlyCustomer Impact
This change provides developers who prefer the code-behind model with an automatic way to generate both files when creating new Razor components, matching the existing functionality available for Razor Pages. This addresses the specific customer feedback requesting this feature and provides consistency across ASP.NET Core item templates.
The original
razorcomponent
template remains unchanged, ensuring no breaking changes for existing workflows.Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.