I have the following template, created by the Clarius editor. When I right click and do a "Preview Transformation", the values set in the Properties window are properly substituted, but the actual .cs file (in the solution)is NOT generated properly. I also get a compile error:
Error1Running transformation: System.ArgumentNullException: Value cannot be null.
Parameter name: objectToConvert
at Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture(Object objectToConvert)
at Microsoft.VisualStudio.TextTemplating71AC0EACE4EB44F4B73CCBE83655D590.GeneratedTextTransformation.TransformText()C:\TT\TemplateTest\TemplateTest\test.tt11
Does anyone know to fix this?
|
| <#@templatelanguage="C#"#> |
|
| <#@assemblyname="System.dll"#> |
|
| <#@propertyprocessor="PropertyProcessor"name="ClassName"type="System.String,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"#> |
| <#@propertyprocessor="PropertyProcessor"name="TargetNamespace"type="System.String,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"#> |
| <#@propertyprocessor="PropertyProcessor"name="HelloMessage"type="System.String,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"#> |
|
|
| usingSystem; |
| usingSystem.Text; |
|
| namespace<#=TargetNamespace#> |
| { |
| class<#=ClassName#> |
| { |
| publicstaticstringhelloMessage="<#=HelloMessage#>"; |
| |
| staticvoidMain(string[]args) |
| { |
| Console.WriteLine(helloMessage); |
| Console.ReadLine(); |
| } |
| } |
| } |
|
I'm also attempting to run this code to substitute the parameters into the template, but that's not working either. I'm assuming that these issues are related and as soon as I can get the .cs file generating properly that I'll be able to do it through code too.
| publicvoidProcessTemplate(stringSchemaName) |
| { |
| //Preparetemplateparameters |
| vararguments=newDictionary<string,PropertyData>(); |
|
| arguments.Add("ClassName",newPropertyData("MyClass",typeof(string))); |
| arguments.Add("TargetNamespace",newPropertyData("MyNameSpace",typeof(string))); |
| arguments.Add("HelloMessage",newPropertyData("HelloMessage",typeof(string))); |
| |
| //InitializeGAXtemplatehost |
| stringcurrentDirectory=Directory.GetCurrentDirectory(); |
| TemplateHosthost=newTemplateHost(currentDirectory,arguments); |
| host.TemplateFile=Path.Combine(currentDirectory,"ServiceTemplate.tt"); |
|
| //Transformtemplate |
| stringtemplate=File.ReadAllText(host.TemplateFile); |
| ITextTemplatingEngineengine=newEngine(); |
| stringoutput=engine.ProcessTemplate(template,host); |
|
| //Saveoutput |
| stringoutputFile=Path.ChangeExtension(host.TemplateFile,".txt"); |
| File.WriteAllText(outputFile,output); |
| } |
Thanks for any help. I'm stumped.