I have a VS project that contains:
a pre-build action running TextTransform on a template.tt to generate generated.cs
There's now a solution to this problem! Oleg Sych has a post on his blog detailing how to make transform-at-build-time work.
Here's the source: https://web.archive.org/web/20140116193428/http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration/
Basically, you just include the T4 build targets in your project file and set the TransformOnBuild property to true.
Here's the relevant excerpt:
true
Note that the Microsoft.TextTemplating.targets file has to be included AFTER the Microsoft.CSharp.targets.