Hi there
I am writing a T4 template which takes help of few other template to generate the entire stuff. I intend to pass the parameter to my sub-templates in the form of object. However I am getting the error which doesn't seems to be resolving. Please help out -
This is my main T4 file, Host.tt
<<#@ template language="C#" debug="true" hostSpecific="true" #><#@ output extension=".cs" #><#@ Assembly Name="System.Core" #><#@ Assembly Name="System.Design" #><#@ Assembly Name="System.Drawing" #><#@ Assembly Name="System.Windows.Forms" #><#@ Assembly Name="System.Runtime.Serialization" #><#@ Assembly Name="EnvDTE" #><#@ import namespace="System" #><#@ import namespace="System.CodeDom.Compiler" #><#@ import namespace="System.Collections.Generic" #><#@ import namespace="System.Drawing" #><#@ import namespace="System.IO" #><#@ import namespace="System.Linq" #><#@ import namespace="System.Resources" #><#@ import namespace="System.Resources.Tools" #><#@ import namespace="System.Runtime.Serialization"#><#@ import namespace="System.Text"#><#@ import namespace="EnvDTE" #><#@ import namespace="Microsoft.CSharp" #><#@ import namespace="Microsoft.VisualStudio.TextTemplating" #><#@ include file="parameterclass.ttinclude" #><#
string templateFile = this.Host.ResolvePath(@"userclass.ttinclude");
string templateContent = File.ReadAllText(templateFile);
TextTemplatingSession session = new TextTemplatingSession();
var model = new ParameterClass{ Value = "This is value" };
session["Model"] = model;
var sessionHost = (ITextTemplatingSessionHost) this.Host;
sessionHost.Session = session;
Engine engine = new Engine();
string generatedContent = engine.ProcessTemplate(templateContent, this.Host);
this.Write(generatedContent);
#>This is my sub-template, parameterclass.ttinclude
<#@ template language="C#" hostSpecific="true"#><#@ assembly name="System.Core" #><#@ import namespace="System.Linq" #><#@ import namespace="System.Text" #><#@ import namespace="System.Collections.Generic" #><#@ import namespace="System.Runtime.Serialization" #><#+
[Serializable]
class ParameterClass
{
public string Value;
}
#>The userclass.ttinclude looks like this - its empty doing nothing as of now
<#@ template language="C#" #><#@ assembly name="System.Core" #><#@ import namespace="System.Linq" #><#@ import namespace="System.Text" #><#@ import namespace="System.Collections.Generic" #><#@ include file="parameterclass.ttinclude" #><#@ parameter name="Model" type="ParameterClass" #>
However when I generate the code using CTRL+S in VS 2015, I get the below error -
Running transformation: System.Runtime.Serialization.SerializationException: Unable to find assembly 'TemporaryT4Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Server stack trace: at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name) at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm) at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.FixupForNewAppDomain() at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm) at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.VisualStudio.TextTemplating.ITextTemplatingSessionHost.set_Session(ITextTemplatingSession value) at Microsoft.VisualStudio.TextTemplating8767B0B1EB6753537F5610A7C9C00973F2698ACD8F3E714AB22365BD26229B0E220F68F10503C8952BCD87E449D21CD9C7CCB19CBB6BD3AA79439CA1471B420B.GeneratedTextTransformation.TransformText() in C:\Applied\TestApp\DummyApp\Parameter\Host.tt:line 35 DummyApp C:\Applied\TestApp\DummyApp\Parameter\Host.tt 35
I am not sure what I am missing, please help out
Pravin Chandankhede