如何将命名空间添加到我的 T4 脚手架?

Posted

技术标签:

【中文标题】如何将命名空间添加到我的 T4 脚手架?【英文标题】:How do I add a namespace to my T4 Scaffolders? 【发布时间】:2016-05-01 22:59:34 【问题描述】:

当我在包管理器控制台中运行 Get-Scaffolder 时,我得到以下输出:

Name                                Description                                                                                                                       Package                       
----                                -----------                                                                                                                       -------                       
MvcScaffolding.Action               Creates an action method, view model, and view                                                                                    MvcScaffolding.VS2015 1.0.12  
MvcScaffolding.ActionUnitTest       Creates a unit test stub for an action method                                                                                     MvcScaffolding.VS2015 1.0.12  
MvcScaffolding.ActionWithUnitTest   Creates an action method, view model, view, and unit test stub                                                                    MvcScaffolding.VS2015 1.0.12  
MvcScaffolding.AspxView             Adds an ASP.NET MVC view using the ASPX view engine                                                                               MvcScaffolding.VS2015 1.0.12  
MvcScaffolding.Controller           Adds an ASP.NET MVC controller with views and data access code                                                                    MvcScaffolding.VS2015 1.0.12  
MvcScaffolding.RazorView            Adds an ASP.NET MVC view using the Razor view engine                                                                              MvcScaffolding.VS2015 1.0.12  
MvcScaffolding.Views                Adds ASP.NET MVC views for Create/Read/Update/Delete/Index scenarios                                                              MvcScaffolding.VS2015 1.0.12  
T4Scaffolding.CustomScaffolder      Creates an entirely new scaffolder with a PS1 script and a T4 template                                                            T4Scaffolding.Core.VS2015 1...
T4Scaffolding.CustomTemplate        Allows you to modify the T4 template rendered by a scaffolder                                                                     T4Scaffolding.Core.VS2015 1...
T4Scaffolding.EFDbContext           Makes an EF DbContext able to persist models of a given type, creating the DbContext first if necessary                           T4Scaffolding.VS2015 1.0.8    
T4Scaffolding.EFRepository          Creates a repository                                                                                                              T4Scaffolding.VS2015 1.0.8    
BasicModel                          Starts with the existing Data Model and Scaffolds everything needed to get the Entity working                                                                   
Controller                          Adds a Controller and ApiController based on the templates                                                                                                
ControllerUnitTest                  Creates a default unit test for a controller. The controller must exist prior to running this scaffolder                                                        
EmptyModel                          Scaffold an empty Model                                                                                                                                         
Module                              Creates default module controller, service, model, view model and views                                                                                         
RegisterService                     Register the Service to the Service Interface in the MainContainer class                                                                                        
Service                             Adds a Service and Service Interface based on the templates     

最后几个脚手架,即:BasicModel、Controller 等……是我自己定制的脚手架。如何让它们显示为 Custom.BasicModel、Custom.Controller 等?

【问题讨论】:

【参考方案1】:

这其实很简单!它不是典型意义上的命名空间。这只是文件名。所以 MvcScaffolding “命名空间”中的脚手架都有文件名,例如“MvcScaffolding.Views”。

通过将我的 PS1 文件的名称更改为“Project.COntroller”,我能够为我的脚手架添加一个“命名空间”。

【讨论】:

以上是关于如何将命名空间添加到我的 T4 脚手架?的主要内容,如果未能解决你的问题,请参考以下文章

如何避免 Rails 脚手架将模型放入命名空间

如何访问 Windows.Storage 命名空间?

如何从 Meteor 包导出到我的应用程序的命名空间?

EF 5.0 修改T4模板

ASP.NET 命名空间

将表单放入命名空间会导致MissingManifestResourceException