Everything below is in addition to the features and changes I noted in my previous post, What’s new with T4 in the Developer Preview of Visual Studio 11?
OK, here goes…
- Directive processors are MUCH easier to build and more flexible
Directive processors are T4’s plug-in mechanism. They allow you to inject code into a template to pass and initialize parameters, or provide standard constructs within a template in a language-agnostic manner. However, they’ve been a bit fiddly to set up in the past and haven’t seen a lot of use. This time, we’ve made them much cleaner and easier.
- Directive processors can now be deployed as simple MEF components in a standard Visual Studio VSIX container. This means you can easily publish them on the Visual Studio gallery. There are new attributes [DirectiveProcessor] and [SupportedDirective] to make this easy. Look out for an example soon.
- Directive processors can now be built to run across Visual Studio versions as they only need to implement the new immutable interface type, IDirectiveProcessor.
- Directive processors can now add custom attributes to the underlying T4 class. For example, it’s now really easy to create a directive processor to decorate a runtime template with MEF exports. You simply implement the new method GetTemplateClassCustomAttributes(). I expect Kathleen to be all over this one!
- Cleanliness features for runtime templates
We’ve finished the name transition from Preprocessed to Runtime templates in the beta including renaming the item templates and, as we’re now seeing a lot more usage of runtime templates, we’ve added a few cleanup features.
- You can now control the visibility of the generated class, using the new visibility property on the <#@ template #> directive with values public or internal. This means that if you’ve got runtime templates as part of a published assembly, they no longer have to be part of your public API.
- You can now turn off line pragmas for runtime templates with the new linePragmas property on the <#@ template #> directive with values true or false. This gives you more debugging options, as you can choose to either debug the original template or the generated code. This can also help if you’re finding the absolute filenames in pragmas are causing distracting merges under source code control.
- UI Simplification
As part of Visual Studio 11’s overall effort to simplify the UI, we’ve moved the Transform All Templates button out of the previously cluttered Solution Explorer toolbar. You’ll now find it on the build toolbar and the build menu. It also blocks the UI a bit less than it used to when you have lots of templates in your solution.