0

I am trying to use T4 for source code generation. Mostly, I am able to generate individual files using it. How do I create a complete Visual Studio directory (preferably separate from the T4 template directory) having the below sample structure:

/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.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ajit Singh
  • 1,016
  • 13
  • 26
  • More clarification, in the above sample, i have the various class definitions (class names, property type/names etc) that are stored in a database. The source code needs to be generated and put in lib folder. Generate the corresponding SQL Scripts and nHibernate codes in DB folder. Put the logs in Logs folder etc. – Ajit Singh Jan 13 '10 at 11:48

2 Answers2

1

You may take a look at the Guidance Automation Extensions and Toolkit for Visual Studio from Microsoft. They are intended for exactly that purpose to be able to author project and solution generation wizards and leverage T4 a lot. In fact, they are the reason why T4 came into being in the first place. However, as they can be seen as a "Software Factory Factory", they do have a steep learning curve.

herzmeister
  • 11,101
  • 2
  • 41
  • 51
  • Would it allow the entire Visual Studio Directory and source code to be generated pro grammatically? Do they have APIs/libraries for this? – Ajit Singh Jan 13 '10 at 09:51
  • Do you mean creating an over-all source tree that every developer should adhere to? I'm not sure but I'm afraid not so easily, as templates you would create with the Guidance Automation are more Project or Solution based. But then again, it's been a long time since I took a look at it, and I didn't go very deeply, so I can't say which fancier tricks you can do with it. – herzmeister Jan 13 '10 at 10:11
  • I checked Guidance Automation and seems like it wont work since it needs visual studio, since it is an extension of it. I need to create the entire project directory from a .NET code that can run without visual studio. – Ajit Singh Jan 13 '10 at 12:06
  • [Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.](http://stackoverflow.com/help/how-to-answer). – Erik Philips May 24 '16 at 17:26
0

As herzmeister der welten mentions, I do think Guidance Automation could do this sort of job, but it is quite a learning curve.

Here are a couple of other options:

  1. Damien Guard has a post on how to generate Multiple outputs from T4. However, it's probably not well-suited for creating lots of different types of files. If you have many files to create of a similar type (e.g. several code files, various project files, etc) that you want to create, his technique would be quite useful.
  2. Another option would be to combine your existing T4 templates and knowledge and create your outputs using command line T4. For example, you could simply use a .bat file that executes various commands to generate the necessary outputs using T4 and your existing templates. The downside here is that it is difficult to pass arguments into the command line utility, but there are some workarounds to that problem too.
Community
  • 1
  • 1
Chris Melinn
  • 2,046
  • 1
  • 17
  • 18
  • [Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.](http://stackoverflow.com/help/how-to-answer). – Erik Philips May 24 '16 at 17:26