Mac experience asp.net 5 beta2 K-Gen code generation _ self-study Process

Source: Internet
Author: User
Tags generator

asp.net 5 Beta2 Adds a new feature that allows you to generate MVC code via the K command, such as K Gen Controller-name HomeController.

If you use Visual Studio, you naturally disagree with this feature, because Visual Studio has done it for you.

If you're using a Mac, you don't have Visual Studio, you don't have K studio, you don't want to be abusive. This feature is worth paying attention to as the MVC code that can be generated from the template.

As a result of the ASP.net code for the Mac has been coveted for a long time, the discovery of this feature, immediately want to try. But there is no relevant information on the Internet, you can only fumble.

First, in the dependencies of Project.json, change all 1.0.0-beta1 to 1.0.0-beta2, which is the package that is upgraded to ASP.net 5 Beta2.

{"
  dependencies": {"
    Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics": " 1.0.0-beta2 ",
    " Microsoft.AspNet.Hosting ":" 1.0.0-beta2 ",
    " Microsoft.AspNet.Server.WebListener ":" 1.0.0- Beta2 ",
    " Microsoft.AspNet.StaticFiles ":" 1.0.0-beta2 "
 }
}

The next step is to add the Gen function (K gen) to K, add the following configuration in the Project.json commands, and tell K to find this command in Microsoft.Framework.CodeGeneration's bag:

{
  "commands": {"  
   gen": "Microsoft.Framework.CodeGeneration"
  }
}

The next step is to download the Microsoft.Framework.CodeGeneration bag, which is KPM's job, adding a reference to Project.json in dependencies, and running KPM restore:

{
  "dependencies": {"Microsoft.Framework.CodeGeneration":  
    "1.0.0-beta2"
 }
}

KPM Restore

Originally thought this is done, the result runs K gen Controller-name HomeController but appears the error prompt:

No code generators found with the name ' controller '

So I got stuck in here and almost gave up.

Later, think of the possibility of a special package for controller code generation, github browse asp.net repo list when found an dongdong:

Scaffolding-code generators to speed up development

Maybe this job is scaffolding. On the ASP.net Scaffolding home page, see a blog link--how to customize scaffolding templates for ASP.net vnext, read this blog after the Epiphany, The original controller code generation is owned by MICROSOFT.FRAMEWORK.CODEGENERATORS.MVC.

So, add the MICROSOFT.FRAMEWORK.CODEGENERATORS.MVC in the Project.json dependencies:

{"
  dependencies": {"
    Microsoft.Framework.CodeGeneration": "1.0.0-beta2",
    " MICROSOFT.FRAMEWORK.CODEGENERATORS.MVC ":" 1.0.0-beta2 " 
  }
}

Then KPM restore, the result nuget/myget server convulsions, restore one afternoon plus evening, until the 2nd morning before restore succeeded.

Then run K Gen Controller-name HomeController, the success:

Finding the generator ' controller ' ...
Running the generator ' controller ' ...
Added Controller:/controllers/homecontroller.cs
Adding dependency Microsoft.AspNet.Mvc of version 6.0.0-* to the AP Plication.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.