In Ruby on Rails, you can create controllers using something like the following on the command line:
$ rails generate controller ControllerName action1 action2 ...etc
Is there something similar in dotnetcore cli for creating controllers?
From what I can find, dotnetcore cli seems rather limited in the commands you can do. I found some of the Microsoft docs about the cli extension, but I'm not sure how to do this for such a team.
UPDATE
Using the @Sanket answer, I was able to create controllers for my dotnetcore application. However, I encountered an error
Package Microsoft.Composition 1.0.27 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.Composition 1.0.27 supports: portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259) One or more packages are incompatible with .NETCoreApp,Version=v1.1.
To solve this problem, I added "net451" to the frame import statement for the netcoreapp1.1 dependency.
My simple project.json file for my empty project (using the @Sanket project.json template) looks like this:
{ "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": { "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.1.0-preview4-final", "type": "build" }, "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { "version": "1.1.0-preview4-final", "type": "build" }, "Microsoft.AspNetCore.Mvc": "1.0.0-*", "Microsoft.AspNetCore.StaticFiles": "1.0.0-*" }, "tools": { "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final", "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final", "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.1.0-preview4-final", "imports": [ "portable-net45+win8" ] } }, "frameworks": { "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.1.0" } }, "imports": [ "netcoreapp1.1", "net451" ] } } }
After starting (in the terminal) $ dotnet restore I can run the following command to create the base controller.
$ dotnet aspnet-codegenerator --project . controller -name SimpleController dotnet aspnet-codegenerator --project . controller -name SimpleController
This created an empty SimpleController.cs controller with the following code: (Note that my dotnet project was called ToolsAppDotNetCore )
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; namespace ToolsAppDotNetCore { public class SimpleController : Controller { public IActionResult Index() { return View(); } } }
@Sanket's answer contains more detailed information about the controller parameters generated by the code.