Thursday, November 06, 2008

T4 Strangeness in VB.NET and Visual Studio 2008

I was writing a quick T4 template in Visual Studio 2008 in a VB.NET project and noticed a few quirks/differences when compared to a C# project.

When you add a text file named “Test.tt” in a C# project, Visual Studio processes the T4 template and generates a corresponding “Test.cs” file:

Test.tt

I expected similar behavior in VB.NET, but I was quite disappointed.  For starters, I didn’t see any apparent output.  To fix this little issue, I had to click on the “Show All Files” button on the Solution Explorer.  Then the file showed up, but I was even more confused because I saw this:

Test.tt.vb

Apparently, the default file extension for T4 templates is “.cs”, so this shouldn’t have really surprised me, but I found it odd that in my VB project, I would have a C# file.  Fortunately, the fix is quite simple: add an output processor directive to the T4 file so that the file extension is “.vb”:

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

That’s it.  I hope this post saves a poor soul some time.

 |  Fernando Cardenas  |  #    |  Comments [4]  | 
Thursday, May 28, 2009 6:27:49 AM (Mountain Standard Time, UTC-07:00)
>>That’s it. I hope this post saves a poor soul some time.

Yes, you did!
Monday, July 27, 2009 10:32:20 PM (Mountain Standard Time, UTC-07:00)
Thanks for this useful blog.
Monday, August 03, 2009 11:09:05 AM (Mountain Standard Time, UTC-07:00)
I will put some into my telephone. So far I am listening to "I Will Touch The Sky".
I am from Cameroon and also am speaking English, give please true I wrote the following sentence: "Profile benefits of online dating servicesin these past few years the trend in dating from all over the world has changed drastically.Online dating service is the best place to find christian single women or men for free."

With love :o, Sedric.
Friday, November 20, 2009 10:09:30 PM (Mountain Standard Time, UTC-07:00)
Very interesting site. Hope it will always be alive!.
I am from Tajikistan and , too, and now am writing in English, give true I wrote the following sentence: "This sam may not be disclosed, abolished, pulled, led, or did by an code in holding lived by the ownership against whom loan of $175 escrow, insurance, transfer, financing, or paperwork is registered, mortgage note."

With best wishes 8-), Neptune.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview