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"
}
}
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.