Pain Free T4MVC
Here is how to get T4MVC to run every time you build, without the mark-as-dirty hack or any Visual Studio support:
Download and install the prerequisites.
Unfortunately, Plain-old-VS2010 does not have the ability to run T4 Templates on every build built-in, so we have to rely on an external toolkit to help us along. On the bright side, it's just the Visual Studio SDK (which you might already have) plus an additional little tidbit.
These must be installed in order, and you should probably exit VS to do so:
Start Visual Studio and open your project file for editing.
Right-click on the project in question, and choose "Unload Project"; this will make it show up as "(unavailable)". Now, you can right-click it again and choose "Edit YourProject.csproj".
Add the relevant sections to your project file.
Set the following properties in your project:
language: xml <MvcBuildViews>true</MvcBuildViews> <TransformOnBuild>true</TransformOnBuild>
The result should look something like this:
Add the toolkit magic as an MSBuild import:
language: xml <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" />
Again, here is a visual of the result:
Save your changes and reload your project.
Right-click your project, which should still be showing as "(unavailable)", and Voila! Your T4 templates will re-gen on every build!
"That's pretty great," you say, "but will it work on my build server?"
Yes, it will work! You simply need to follow the MSDN instructions for this. Just a few files need to be copied on to the build server.
I hope this helps people get the most out of MVC. Your feedback is welcomed.