AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Writing a custom scaffolder using aspnet-codegenerator...

Open gkochanowsky opened this issue 5 years ago • 13 comments

I think is possible to create a custom scaffolder. It would be nice if there were some documentation as to how to do this. The out of the box scaffolders are nice but they are really just a starting point for an organization specific scaffolder.

[Please don't close this base on an issue posted on your very first version of Core from four years ago after four year of changes. That is a very thoughtless thing to do. Besides that post was based on a hack I made. I'm trying to use whatever extensiblity that exists in aspnet-codegenerator.]

gkochanowsky avatar Feb 25 '20 18:02 gkochanowsky

@gkochanowsky can't you just fork https://github.com/aspnet/Scaffolding and modify the scaffolder?

@deepchoudhery would have to write the doc, and I don't think he has time.

Rick-Anderson avatar Feb 27 '20 04:02 Rick-Anderson

@gkochanowsky Why not create a template to use with dotnet new? Both item and project templates are supported. The documentation is at https://docs.microsoft.com/dotnet/core/tutorials/cli-templates-create-item-template.

scottaddie avatar Feb 27 '20 15:02 scottaddie

@scottaddie I looked at that. Maybe I'm mistaken, but isn't that is a facility for generating a project from scratch? I'm looking for something to generate code in an existing project from one or more models. Would dotnet new that work? If so how would you make it work?

gkochanowsky avatar Feb 27 '20 15:02 gkochanowsky

@scottaddie I looked at that. Maybe I'm mistaken, but isn't that a facility for generating a project from scratch? I'm looking for something to generate code in an existing project from one or more models. Would dotnet new work for that? If so how would you make it work?

gkochanowsky avatar Feb 27 '20 15:02 gkochanowsky

@gkochanowsky The dotnet new approach is capable of adding code to an existing project. Custom parameters can be defined to pass data into the template. What kind of code do you want generated, and what information would be inferred from the existing models?

scottaddie avatar Feb 27 '20 15:02 scottaddie

@scottaddie, I'm looking for similar functionality to aspnet-codegenerator functionality when a model is specified in terms of using reflection to determine all the properties of a model class and using that to generate code for many files.

gkochanowsky avatar Feb 27 '20 17:02 gkochanowsky

@scottaddie, I'm also looking for it to work from a project local template directory that can be modified by the user specifically for that project.

gkochanowsky avatar Feb 27 '20 18:02 gkochanowsky

@vijayrkn What do you recommend for @gkochanowsky? I don't think this is easily accomplished with dotnet new.

scottaddie avatar Feb 27 '20 21:02 scottaddie

we can (and plan to use) dotnet new for very simple scaffolders (empty controllers, and views) but for scaffolders that have model reflection, we have to use aspnet-codegenerator.

deepchoudhery avatar Feb 27 '20 21:02 deepchoudhery

@deepchoudhery, I've forked the project, how to I develop and debug with it?

gkochanowsky avatar Feb 28 '20 16:02 gkochanowsky

I would also be interested in knowing how to add custom scaffolders either to aspnet-codegenerator or Visual Studio. Can't find the documentation anywhere.

thestonehead avatar Nov 13 '20 21:11 thestonehead

I came across this article which explains how it is done. Worked perfectly well for me for overwriting view templates.

daviddionys avatar Aug 03 '22 14:08 daviddionys

I have seen this method before, but this only overrides existing templates. I wanted to make entirely new ones.

thestonehead avatar Aug 03 '22 16:08 thestonehead

Feel free to create an issue in https://github.com/dotnet/Scaffolding/issues

Rick-Anderson avatar Sep 30 '22 03:09 Rick-Anderson