title: Simple & Practical C# code generation (VS 2008 or 2010)
body: <p>I've put off using generated code as part of the build process for fear of the complexity it introduces into the build process.</p>
  
  <p>Is there a simple way to integrate build-time generated code into an app?</p>
  
  <p>The kind of code I'm thinking of is <strong>similar to the resource and settings file</strong> code generation that Visual studio performs:</p>
  
  <ul>
  <li>Having intellisense here is valuable</li>
  <li>There are a lot of properties and links between properties that are trivial to describe, but impossible to implement tersely in C#.</li>
  <li>The underlying resource is be modifiable and the code is automatically regenerated without needing any user interaction and without any need to understand the internals of the generator.</li>
  </ul>
  
  <p><strong>For (a non-real-world) example</strong> consider a precompiler that generated accessor to the named capture groups of a Regex via similarly named C# properties (or methods).  This is typical of the kinds of things I'd like to generate: long snippets of boilerplate wrappers whose primary function is to enable compile time checking for errors (in the above; accessing non-existant capturing groups or writing and invalid regex) and no less importantly, intellisense for these properties.  Finally, <strong>this setup should be trivially usable by others on the team</strong> with only the bare minimum of learning curve.  I.e., it's absolutely not acceptable to require manual intervention to regenerate the code, nor acceptable to commit the generated code into source control.  At worst, everyone should just need to install some extension; ideally the extension should be installable into the source-tree so that anyone that checks out the tree can build the project without any introduction.</p>
  
  <p>For that to work well, it's critical that the IDE integration be excellent: <strong>Updating the underlying "resource" definition file should trigger a regeneration</strong>  of the code without any user interaction, and ideally the generator itself would be easy to maintain for other developers later on (i.e. some amount of generator debug-ability is a plus).</p>
  
  <p>Finally, an XSLT-like approach where <strong>the same template can be applied to various input resources</strong> is ideal; both because this means that you don't even need to look at the actual generator code if all you want to do is is update the resource, and because it makes template reuse trivial.</p>
  
  <p><strong>I've looked at T4, but</strong> from what I've seen this has a less handy ASP-like approach where template and resource aren't cleanly split (i.e, the generator is responsible for finding the resource - which makes template reuse less easy).</p>
  
  <p>Is there a better (cleaner) solution or some way of running T4 such that the same template is can be trivially reused and (much like .NET settings files) that any update of the resource automatically triggers a regeneration of the implemented code?</p>
  
  <p><strong>Summary:</strong>
  <em>I'm looking for a code-gen approach that can</em></p>
  
  <ol>
  <li>Regenerate code automatically without dev intervention when the underlying <em>resource</em> (not the template!) changes.</li>
  <li>Be somewhat simple to maintain</li>
  <li>Be able to share the same generator template between several resources (which, with point #1 probably implies the resource should refer to the generator and not vice-versa).</li>
  </ol>