I am using Visual Studio 2010 TextTemplatingFileGenerator custom tool to generate C# code (.cs) and would like to know if is there a way of preventing a given .tt from being completely generated upon a given programmatic condition.
I want to achieve the following:
- Sometimes I want to generate a regular editable class;
- Other times I want to generate a pair of classes to represent a parent-child relation, each of them implementing their specific set of rules required by their role.
Before answering, please bear in mind that DO NOT intend to use TextTemplatingFilePreprocessor – I already have explored its strengths and weaknesses. Although is suitable for other scenarios, is not for my current context. So I really want to stick to TextTemplatingFileGenerator.
If you can live with a minimal stub file being generated for all of A, B, C (or alternatively one ‘control’ file that always generates a minimal stub) then you can do this directly with T4 using something like Damien Guard’s multiple file output technique.
http://damieng.com/blog/2009/11/06/multiple-outputs-from-t4-made-easy-revisited
This can be controlled programmatically from your template.