views:

151

answers:

3

I have a SQLite database and SubSonic3, finally got a clue on how to generate the .cs from the .tt in Visual Studio. My stuff builds now.

I can kick off MSBuild automatically to build my project, but I would like to add a pre-build event to regen the ActiveRecord.cs cleanly so any database changes end up there for future Unit tests.

How can I simulate the 'run external tool' in the Visual Studio GUI?

Thanks.

A: 

You can run the TextTemplating tool from the command line:

C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.2\TextTransform.exe "path/to/your/ttfile.tt" -out <outFileName>

Use TextTransform.exe /help for more command line arguments you can use.

womp
SubSonic requires that you run it's t4 templates from within visualstudio so you can't run them succesfully from the commandline.
Adam
I don't understand why SubSonic requires this. I found this link but am not sure if it applies either.http://geekswithblogs.net/EltonStoneman/archive/2008/07/25/an-msbuild-task-to-execute-t4-templates.aspx
ScSub
A: 

At this time, the SubSonic's Settings.ttinclude file must be run from within the VisualStudio application, and can not be run from the command line. This is because Settings.ttinclude uses the project context to locate the App.config / Web.config file so that it can look up the connection string.

Attempting to run via command line using TextTransform.exe will result in the error:

error : Running transformation: System.InvalidCastException: Unable to cast object of type 'Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost' to type 'System.IServiceProvider'.

This stems from this method in Settings.ttinclude:

public EnvDTE.Project GetCurrentProject()  {
    IServiceProvider _ServiceProvider = (IServiceProvider)Host;
    ...
}
rally25rs
A: 

By hacking the Settings.ttinclude file, you can set up Subsonic to run from the command line.

Just modify it to set your connection string as the return value of GetConnectionString and taking out all other logic.

James