Tuesday, March 16, 2010

T4MVC Add-In to auto run template

6/2/2010 Update - Project enhanced and now on codeplex!   http://chirpy.codeplex.com/

T4MVC is a fantastic solution to avoid 'Magic Strings' in ASP.NET MVC.   





Thanks to David Ebbo for this contribution which has made its way to MVCContrib.  


Must keep T4 template open and save it once.
This has been the only negative thing about the template.  I thought about writing an Add-In for VS to do this and even taked to David about doing it.  Well, his latest post has inspired me to write one.  I took my dot net less plug in and ripped nearly everything out of it, threw in about 5 lines of new code and it is done.

Configuration
There isn't any.  Just install the add-in and it should work.  It watches for any save, add, or remove event to the solution and runs the T4 template at that time.  As long as you have the T4MVC.tt file in  your project it will run.






Source
I have attached the source and binaries.  I am sure there are some improvements we all can make.


Installation
Simply download the file and double click to install into your Visual Studio Add-in folder.  Currently I only have tested this for VS2008, however should be easy to make work on 2010.  Full Source

What do you think?

Shout it
kick it on DotNetKicks.com

11 comments:

Anonymous said...

Very nice, thanks!

Paul Blamire said...

Works brilliantly, thanks. The old method hadn't caused me any real problems but this is much better. Nice

Carl said...

thanks, would've been even easier with a .vsi(x) file tough

Wayne Brantley said...

@Carl,
Good idea. Done...download link is now a .vsi file.

Robert said...

Has anyone tested in vs2010?

Wayne Brantley said...

To make work in VS2010, just change the version in the .AddIn XML file from 9.0 to 10.

Unknown said...

The add-in requires Full Trust, so it will die with "The add-in T4MVCAddIn.AddIn failed to load or caused an exception. Would you like to remove this add-in? {full UNC path} Error number 8013150a" if your VS2008 Addins folder is on a UNC. A workaround is here: http://forum.huagati.com/topic49-load-error-8013150a-if-userprofile-is-a-unc-path.aspx This isn't really the fault of Addin, but an environment issue.

James Maroney said...

Thanks Wayne! This is certainly a very helpful plugin.

For others like me that didn't quite understand how to make it work in VS 2010 - here's the key piece of information: .vsi files are just zip archives.

Unzip the .vsi, make the change to the .AddIn XML file that Wayne mentioned, rezip and rename to .vsi. Then when you install the plugin, it will be available to VS 2010.

Wayne Brantley said...

James - see my other post and it contains a VS integrated installer too.

http://blog.waynebrantley.com/2010/07/t4mvc-add-in-and-resource-compression.html

Anonymous said...

Productivity boost with this awesome plug-in!

Worked 100% with VS2008, I just want to add that after downloading and installing, you need to restart VS, at least, I needed!

Thanks!

Stacy Morley said...

Great read thank yyou