Instruct T4 to use C# v3.5

Consider this simple T4 template:

<# for (var i = 0; i < 10; ++i) { WriteLine("hello"); } #>

Trying to build the project results in a compilation error because ‘var’ is an unknown type. A bit of research learned me that i should instruct the processor to use a specific c# version like this:

<#@ template language="C#v3.5" inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"  #>
<# for (var i = 0; i < 10; ++i) { WriteLine("hello"); } #>

Problem solved :)

This entry was posted in C#, Visual Basic. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>