dotnet / dotnet/Scaffolding

How do I override the default Blazor scaffolding template in Visual Studio 2022

Open
#2,803 4 comments 0 reactions 0 assignees View on GitHub
area-blazor area-scaffolding customer-reported
Dominant language
C#
Stars
818
Forks
260
Avg merge
1d 8h
Merged PRs (30d)
10

Description

I want to edit the scaffolding template for Blazor CRUD pages, but my changes to the template are not being reflected in the output.

I tried researching this issue, and [the closest answers I could find](https://davecallan.com/override-the-default-controller-scaffold-templates-in-visual-studio-2019-and-net-5-0/) are how to edit Razor templates, or MVC component templates. I tried following these instructions, adapting to my project (I copied the Blazor folder (C:\Users\username.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\8.0.2\Templates\Blazor) instead of Razor into a folder in my project called Templates, hierarchy shown here: )

![image](https://github.com/dotnet/Scaffolding/assets/159244810/2b44accb-ec9e-4f26-af5e-f5a237c25b03)

and then I changed the header of the Create.tt file (to MudBlazor's header text) to test if it would work:

```
Create

Create was changed

<#= modelName #>



```

but I noticed upon saving, a file named Create.cs would be created in the same folder:

![image](https://github.com/dotnet/Scaffolding/assets/159244810/3bd53944-59c0-41fb-a9c1-e7472e8645f8)

with the only contents being

`ErrorGeneratingOutput`

and attempting to scaffold would give an error. I tried deleting the Create.cs file, and starting again, but it seemed like it used the default template instead of my override. I then changed the template inside the installation directory(C:\Users\username.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\8.0.2\Templates\Blazor), and tried scaffolding again, but again, no changes were shown in the output. What am I doing wrong?

Not sure if this is at all relevant, but Visual studio is spitting out these errors since I copied the template into my project:

![image](https://github.com/dotnet/Scaffolding/assets/159244810/44fc53b3-a2a5-4a57-bada-5b9017248a2a)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.