In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to achieve K gen code generation of ASP.NET 5 beta2 in Mac". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve K gen code generation of ASP.NET 5 beta2 in Mac".
A new feature has been added to ASP.NET 5 beta2 to generate MVC code through the K command, such as k gen controller-name HomeController.
If you are using Visual Studio, you will naturally disapprove of this feature, because Visual Studio does it for you.
If you are using Mac, no Visual Studio, no K Studio, and do not want to abuse the MVC code that can be generated through templates, this feature is worth paying attention to.
Since I have been salivating over writing ASP.NET code under Mac for a long time, as soon as I found this feature, I immediately wanted to give it a try. But there is no relevant information on the Internet, so I have no choice but to explore it by myself.
First, change all 1.0.0-beta1 to 1.0.0-beta2 in project.json 's dependencies, that 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 to the commands of project.json, and tell K to find this command in the Microsoft.Framework.CodeGeneration package:
{"commands": {"gen": "Microsoft.Framework.CodeGeneration"}}
The next step is to download the Microsoft.Framework.CodeGeneration package, which is what KPM does, add a reference to project.json in dependencies, and run kpm restore:
{"dependencies": {"Microsoft.Framework.CodeGeneration": "1.0.0-beta2"}} kpm restore
I thought this would be done, but there was an error when running k gen controller-name HomeController:
No code generators found with the name 'controller'
So I got stuck here and almost gave up.
Later, I thought that there might be a special package for controller code generation, and when I browsed ASP.NET Repo List on GitHub, I found something:
Scaffolding-code generators to speed up development
Maybe Scaffolding did the job. I saw a link to a blog on the ASP.NET Scaffolding home page-How to customize scaffolding templates for ASP.NET vNext. After reading this blog post, I suddenly realized that Microsoft.Framework.CodeGenerators.Mvc was responsible for the code generation of controller.
So, add Microsoft.Framework.CodeGenerators.Mvc to the dependencies of project.json:
{"dependencies": {"Microsoft.Framework.CodeGeneration": "1.0.0-beta2", "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta2"}}
Then kpm restore, as a result, the nuget/myget server twitches, restore an afternoon plus evening, and restore is not successful until the next morning.
At this point, run k gen controller-name HomeController again, and it will be successful:
Finding the generator 'controller'...Running the generator' controller'...Added Controller: / Controllers/HomeController.csAdding dependency Microsoft.AspNet.Mvc of version 6.0.0 Murray * to the application.
Thank you for your reading, the above is the content of "how to achieve K gen code generation of ASP.NET 5 beta2 in Mac". After the study of this article, I believe you have a deeper understanding of how to achieve K gen code generation of ASP.NET 5 beta2 in Mac, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.