This project is read-only.


Cannot automate project build when using T4MVC


The T4MVC template throws an exception "T4MVC can only execute through the Visual Studio host" if it is transformed outside of Visual Studio. This makes automation of the project build very difficult when using msbuild and tools such as CruiseControl.NET.

It is now possible to transform T4 templates as part of the build process using the T4 MSbuild integration that comes with the Visual Studio 2010 Visualization and Modeling SDK. See Oleg's post on this at These extensions modify the build process of a project to perform T4 transformation before compiling the source and you no longer need to edit/save the tt file to get changes updated. However, the T4MVC template fails when run in this manner as it thinks it is not in the Visual Studio Host.

Our organisation, and probably many others, need to be able to transform T4 templates during the build process and in particular during our automated build processes. Currently the T4MVC template makes this impossible. We have to commit the generated files to source control and manage the many commit conflicts that occur as a result.

The T4MVC template should support execution outside the Visual Studio Host environment. We can't live without T4MVC or our automated builds, but they currently can't live together!
Closed Oct 24, 2010 at 11:44 PM by davidebbo
T4MVC heavily depends on the VS Host as it needs to get information about the code file, so it will realistically never run outside of VS. However, this is typically a non-issue, because the template is meant to be executed at development time, and the resulting files are meant to be checked in. So there really is no reason to process the template at build time.


gmaughan wrote Oct 25, 2010 at 10:49 PM

David, I'm disapointed that you closed this issue. Your comment that "this is typically a non-issue" is incorrect. It is an issue for us. And I believe it is an issue for others. I notice that a similar issue was closed on this some time back. The T4MVC template includes a hack to keep it dirty so that your development-time requirement works. This hack doesn't work well. We find that every developer needs to edit this file in their local copy before updates occur. If the template could be compiled as part of the build process then this wouldn't be needed. Not to mention the code conflicts we get on this file because of the edits.

If, as you say, T4MVC heavily depends on the VS Host, then perhaps Visual Studio needs to be enhanced so that T4 templates can be processed during every build. You are an architect on the ASP.NET team, you could make it happen.

vinneyk wrote Jul 9, 2014 at 7:58 PM

@DavidEbbo, is this not even possible by pulling the relevant resources into the build server as suggested by Code Generation in a Build Process?

davidebbo wrote Jul 9, 2014 at 8:47 PM

I don't think so. You can get all the text templating engine parts, but what's missing is the VS Host object model.