tags:

views:

361

answers:

2

I'm trying (and failing) to write a simple template file:

<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ output extension="cs" #>
<#@ include file="T4Toolbox.tt" #>
<#@ property name="ClassName" processor="PropertyProcessor" type="System.String" #>

public class <#= ClassName #>
{
}

When I click on the template in visual studio, the property 'ClassName' is there in the properties window. That's what I want! When I enter text in there and build, I get the following error:

 Error  1 Running transformation: System.ArgumentNullException: Value cannot be null.
Parameter name: objectToConvert
   at Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture(Object objectToConvert)
   at Microsoft.VisualStudio.TextTemplating32ED7F6BD49D2C3984C2CB7194792D4B.GeneratedTextTransformation.TransformText() in c:\Users\neilt.PAV12\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\ClassMaker.tt:line 6  C:\Users\neilt.PAV12\Documents\Visual Studio 2008\Projects\ConsoleApplication2\ConsoleApplication2\ClassMaker.tt 1 1

Hopefully, you can see what I want to do: I'd like my template to spit out a .cs file with a class named with the string I set in the property window in visual studio. Sadly, I am failing at a very early step!!

A: 

There appears to be some insight into this problem here:

http://social.msdn.microsoft.com/Forums/en-US/vsgatk/thread/f0059983-62dd-4e98-b714-170e7ae2c32c

Robert Harvey
Thanks for the information although it doesn't work. I think the issue there is that the guide they link to is very sketchy and doesn't really explain the solution very well.
Neil Trodden
A: 

Last time I tried, this scenario didn't work because there is no standard processor for the property directive and no support it in Visual Studio. You may be using the limited support provided for this directive by the Clarius T4 editor; I remember getting a similar error.

Oleg Sych
So there is no way to do this?I was hoping I could use the Visual Studio design time tools, such as the one which allows you to select a database connection, to then pass in the database my template generator needs to create a DAL for me.Is just setting the database name in my template by hand the only way I can do this?
Neil Trodden