I am trying to write my own code generator for the dotnet kernel, but so far have not had much success with limited documentation around it.
I worked a bit with the source code of CodeGeneration, figured out how to run generators from the command line and how it works inside.
Since the generators available in the dotnet kernel will not satisfy my needs, I tried to write my own CodeGenerator, but I didn't seem to be able to call it through the "dotnet aspnet-codegenerator" command. Below is my custom code generator (currently has no implementation - my goal is to be able to run this from dotnet cli and end the exception)
namespace TestWebApp.CodeGenerator
{
[Alias("test")]
public class TestCodeGenerator : ICodeGenerator
{
public async Task GenerateCode(TestCodeGeneratorModel model)
{
await Task.CompletedTask;
throw new NotImplementedException();
}
}
public class TestCodeGeneratorModel
{
[Option(Name = "controllerName", ShortName = "name", Description = "Name of the controller")]
public string ControllerName { get; set; }
[Option(Name = "readWriteActions", ShortName = "actions", Description = "Specify this switch to generate Controller with read/write actions when a Model class is not used")]
public bool GenerateReadWriteActions { get; set; }
}
}
The following shows how I try to call the code generator,
dotnet aspnet-codegenerator -p . TestCodeGenerator TestController -m TestWebApp.Models.TestModel
or
dotnet aspnet-codegenerator -p . test TestController -m TestWebApp.Models.TestModel
, , , , . . ,
Finding the generator 'TestCodeGenerator'...
No code generators found with the name 'TestCodeGenerator'
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGeneratorsLocator.GetCodeGenerator(String codeGeneratorName)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:06.23
CogeGenerator ?
Repro: Github