dotnet / dotnet/Scaffolding

How can I make Visual Studio 2022 use my custom controller templates?

Open
#1,955 1 comment 1 reaction 1 assignee Claimed by @deepchoudhery View on GitHub
0 - Backlog area-scaffolding customer-reported
Dominant language
C#
Stars
818
Forks
260
Avg merge
1d 8h
Merged PRs (30d)
10

Description

Hello

I'm not sure if this is the right spot to ask; I'm sorry if it doesn't belong here.

**How can I make Visual Studio 2022 use my custom templates when scaffolding a controller?**

In the root of a newly created ASP.NET Core MVC project (dotnet 6.0.301), I created a folder named `Templates` and copied the `ControllerGenerator` folder form `%USERPROFILE%\.nuget\packages\microsoft.visualstudio.web.codegenerators.mvc\6.0.6\Templates` into it.
I edited the `EmptyController.cshtml` to make the newly created controllers inherit my base controller.
Then I add a reference to `Microsoft.VisualStudio.Web.CodeGeneration.Design` to the project using the VS2022 UI.
Now, if I use `dotnet-aspnet-codegenerator controller -name DummyController -outDir Controllers` to scaffold a new empty controller, it works like a charm; but if I use Visual Studio UI, it generates the default "empty controller."

Is there something I'm missing here?

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.