An even better way to run T4MVC: a VS AddIn

Last week, I blogged about a nice way of auto-running T4MVC by using the Macro IDE to write an OnBuildBegin event handler.  This was a big improvement over the hacky ‘AlwaysKeepTemplateDirty’ flag that we’ve been using since T4MVC’s early days.

Since then, Wayne Brantley has taken this idea to the next level by turning it into a Visual Studio AddIn.  Check out his post and give it a try!

The nice benefits of the AddIn over directly handling VS events in the macro IDE are:

  • Simpler install: you drop a couple files in the AddIn folder and it just works
  • Encapsulation: all the code related to this is in one binary
  • Easy to disable: once the AddIn is installed, you can just go in Tools / AddIn Manager to turn it on or off

Note that Wayne’s AddIn works a bit differently from Joachim’s macro (and from AlwaysKeepTemplateDirty): instead of running when you build the project, it runs as soon as you save a file.  The advantage is that you can just Add a controller action and save the .cs file, and it will instantly be available to your views via T4MVC.

The downside is that it makes saving a little slower, but in practice it seems to be mostly negligible.  But it would be great to hear people’s feedback on this.  If there is a perf issue, we have some ideas on making it faster.

If you use T4MVC, please give this AddIn a try and let us know how it works for you!


Where are we on getting rid of the AlwaysKeepTemplateDirty flag?

In the last post, I also polled people on whether we should just kill this flag.  Mostly, people were ok with that, but some cautioned that we should keep it until the replacement has been show to really work well.  This sounds like a wise decision, and this remains true with this AddIn.  Hopefully the AddIn will work for everyone, and once we’re comfortable enough with that, we can think about killing the old flag.