views:

129

answers:

2

I am trying to use T4 for source code generation. Mostly, I am able to generate individual files using it. Can you please provide me some information on how to create a complete visual studio directory (preferably separate from 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. 
+1  A: 

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 der welten
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
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 der welten
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
+1  A: 

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.
Chris Melinn