使用T4创建visual studio项目目录

时间:2010-01-13 09:11:35

标签: code-generation t4

我正在尝试使用T4生成源代码。大多数情况下,我可以使用它生成单个文件。能否请您提供一些有关如何创建完整的visual studio目录(最好与T4模板目录分开)的信息,其中包含以下示例结构:

/MyProject – Contains MyProject.sln.
/app - Contains the core project layers.
    /MyProject.ApplicationServices
    /MyProject.Core
    /MyProject.Data
    /MyProject.Web
    /MyProject.Web.Controllers
/build - Empty folder for housing build related stuff.
/lib - Contains the solution items for the deployable application.
/db - Contains database schema information; e.g., the result of scaffolding and/or NHibernate's schema export.
/docs - Project documents.
/logs - Output location for log files.
/tests
    /MyProject.Tests
/tools
    /lib - Contains the solution items for the tests project and all other non-deployable assemblies.
    /CrudScaffolding - Customizable CRUD, scaffolding generation code. 

2 个答案:

答案 0 :(得分:1)

您可以查看Microsoft的Guidance Automation Extensions and Toolkit for Visual Studio。它们的目的正是为了能够创建项目和解决方案生成向导并充分利用T4。事实上,它们是T4首先出现的原因。然而,由于它们可以被视为“软件工厂工厂”,它们确实有一个陡峭的学习曲线。

答案 1 :(得分:0)

正如herzmeister der welten提到的那样,我确实认为指导自动化可以做这种工作,但这是一个相当的学习曲线。

以下是其他几个选项:

  1. Damien Guard有一篇关于如何generate Multiple outputs from T4的帖子。但是,它可能不适合创建许多不同的类型文件。如果您要创建许多要创建的类似类型的文件(例如,几个代码文件,各种项目文件等),他的技术将非常有用。
  2. 另一种选择是结合现有的T4模板和知识,并使用command line T4创建输出。例如,您可以使用执行各种命令的.bat文件,使用T4和现有模板生成必要的输出。这里的缺点是很难将参数传递给命令行实用程序,但是问题也存在some workarounds
相关问题