title: How to generate controller using dotnetcore command line
body: <p>In Ruby on Rails, you can generate controllers using something like the following in command line:</p>
  
  <p><code>rails generate controller ControllerName action1 action2</code> <code>...etc</code></p>
  
  <p>Is there something similar in the <strong>dotnetcore cli</strong> for generating controllers? </p>
  
  <p>From what I can find the dotnetcore cli seems quite limited in the commands that you can do. I did find something from Microsoft's docs about extending the cli but I am not confident about how to do that for a command such as this. </p>
  
  <p><strong>UPDATE: Jan 29th 2019</strong></p>
  
  <p><strong>@Jspy</strong>'s answer is the new way of generating controllers using dotnetcore cmd since mid 2018. </p>
  
  <p><strong>UPDATE: Dec 21st 2016</strong></p>
  
  <p>Using <strong>@Sanket</strong>'s answer I was able to generate controllers for my dotnetcore application. However I encountered an error </p>
  
  <pre><code>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.
  </code></pre>
  
  <p>To solve this issue I added <code>"net451"</code> to the framework import statement for the <code>netcoreapp1.1</code> dependency.</p>
  
  <p>My simple <code>project.json</code> file for my empty project (using @Sanket's <code>project.json</code> template) looked like this:</p>
  
  <pre><code>{
    "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"
        ]
      }
    }
  }
  </code></pre>
  
  <p>After running (in terminal) <code>$</code> <code>dotnet restore</code> I could run the following command to generate a basic controller.</p>
  
  <p><code>dotnet aspnet-codegenerator --project . controller  -name SimpleController</code></p>
  
  <p>This generated an <em>empty</em> controller <strong>SimpleController.cs</strong> with the following code:
  (Note that my dotnet project was called <code>ToolsAppDotNetCore</code>)</p>
  
  <pre><code>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();
          }
      }
  }
  </code></pre>