开发者

Syntax Highlighting for .tt files?

Is there any way to tell Visual Studio 2010 to enable syntax highlighting for .tt files? I do have a directive to set the e开发者_如何学Cxtension:

<#@ output extension=".ascx" #>

So I'd like Visual Studio to treat the file as an ascx file for the purpose of Syntax Highlighting.


Try the Tangible T4 Editor extension. There's a free version you can grab to try it out, but if you use them often, it's worth getting the pro license.


ForTea ReSharper plugin

https://github.com/jetbrains/fortea
https://plugins.jetbrains.com/plugin/13469-fortea/

  • Execution of classical T4 templates
  • Generation of C# code (aka template preprocessing)
  • Full intelligent support in T4 directives
  • Full intelligent support in C# in in-line blocks: find usages, refactorings, context actions, etc.
  • Extensive intelligent support for includes
  • Support for adding assembly and import directives through quick fixes
  • Lots of other IDE features: file structure, extend selection, refactorings, etc

To install ForTea, use Extension Manager from the ReSharper menu.

Otherwise Some old ones. Julie Lerman (EF book writer etc..) I recall her talking about one, years ago.


As well as the Tangible editor mentioned above there's also the Clarius one, Visual T4. You can find both on the Visual Studio Gallery and see which one you prefer.


I just downloaded Devart T4 Editor. It seems to work okay, and allows you to customize the syntax colors, as well as provides intellisense. At this time, it's available for every version of Visual Studio from 2008 to 2017.

My only complaint so far is that it doesn't have an option for highlighting C# operators (e.g. <, >, +, etc), or numbers.

Syntax Highlighting for .tt files?


If you don't want to install a plugin or change your file's extension, you can just change the "Editing Experience" for .tt files in the Visual Studio Options.

Go to Tools > Options... > Text Editor > File Extensions, and then add the tt file extension. You can bind it to whatever target language you want. The highlighting might be a little messed up around the template code, and you have to change the target language manually, but it works pretty well for not requiring any new software. Watch out though, because Intellisense's outlining and auto formatting can get really confused by the template code.


No there is not in the 2010 (or before) version of Visual Studio. The T4 templates won't invoke the language service of the template target for highlighting.

The only known editor which does this sub-language highlighting is the ASPX file editor. Doing it requires a very interesting dance between the language service and the ASPX Editor code base. It could certainly be extended to other frameworks like T4 templates but to my knowledge it hasn't been done.


The free T4 Language extension from Brice Lambson available on the Visual Studio Marketplace works well for me in VS 2019, and has nice colors for dark mode while allowing you to easily customize the colors too. It is highly rated by other developers, and reported to work with VS 2022.


(NB this relates to VS2013 not VS2010, but I'm hoping it works for both)

Change the extension of your template file!

Your template files don't need to have the .tt extension (they just need the Custom Tool to be "TextTemplatingFilePreprocessor" or "TextTemplatingFileGenerator"), so what you can do is to change the extension to whatever's most suitable.

I'm templating some javascript at the moment, so I've got some T4 templates with .js extensions.

Highlighting works nicely for the js bits, but obviously looks a bit rubbish for the C# bits and the declarations at the top (red squiggles everywhere). I can live with that!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜