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!!
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.