Error while trying to pass parameter to t4 template
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 a template in visual studio, the "ClassName" property is in the properties window. This is what I want! When I enter text 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
Hope you can see what I want to do: I would like my template to spit out a .cs file with a class named as specified in the properties window in visual studio. Unfortunately, I fail very early on!
a source to share
The last time I tried it , this scenario did not work because there is no standard processor for the property directive and does not support it in Visual Studio. You can use the limited support provided by this directive by the Clarius T4 editor; I remember getting a similar error.
a source to share
There seems to be some understanding of this issue here:
http://social.msdn.microsoft.com/Forums/en-US/vsgatk/thread/f0059983-62dd-4e98-b714-170e7ae2c32c
a source to share