none
T4 An Exception was thrown while processing the template. RRS feed

  • 问题

  • 使用T4模板来进行代码生成,因为要做成个代码代码生成的扩展,所以参照MSDN的示例: http://msdn.microsoft.com/zh-cn/library/bb126579 写了个自定义的处理引擎,本地运行没有问题,但是部署到服务器之后出现了如下的异常错误:

    An Exception was thrown while processing the template.  The following Exception was thrown:
    System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Microsoft.VisualStudio.TextTemplating.AssemblyResolver,Microsoft.VisualStudio.TextTemplating.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
       at System.AppDomain.add_AssemblyResolve(ResolveEventHandler value)
       at Microsoft.VisualStudio.TextTemplating.Engine.CompileAndRunCode(String generatorCode, ITextTemplatingEngineHost host, TemplateProcessingSession session)
       at Microsoft.VisualStudio.TextTemplating.Engine.ProcessTemplateImplementation(TemplateProcessingSession session, String content, ITextTemplatingEngineHost host, String className, String classNamespace)

    这个是调用自定义处理引擎的方法

    public string GenerateCodeByT4(string databaseName, string objectName, string objectType,string baseClass) { CustomTextTemplatingEngineHost host = new CustomTextTemplatingEngineHost(); if (objectType.First2Upper() == "Table") { var talbe = DataBaseHelper.GetTableByName(databaseName, objectName); host.Session = new TextTemplatingSession(); host.Session.Add("Table", talbe); } else { var view = DataBaseHelper.GetViewByName(databaseName, objectName); host.Session = new TextTemplatingSession(); host.Session.Add("View", view); } host.Session.Add("BaseClass", baseClass); host.Session.Add("ItemType", objectType.First2Upper()); host.TemplateFileValue = Path.Combine(Request.PhysicalApplicationPath, "bin", "test.tt"); string path = Path.Combine(Request.PhysicalApplicationPath,"Content","EntityClass.txt"); if (System.IO.File.Exists(path)) { using (StreamReader sr = new StreamReader(path)) { string input = sr.ReadToEnd(); Engine engine = new Engine(); string output = engine.ProcessTemplate(input, host); foreach (CompilerError error in host.Errors) { output += error.ErrorText + "\r\n"; } StringBuilder stb = new System.Text.StringBuilder(); stb.Append("<pre class=\"brush: c#; class-name:'CodeGenerate'\" >"); stb.Append(output); stb.Append("</pre>"); return stb.ToString(); } } return "T4 template doesn't exists"; }

    请各位大大帮忙看看问题,急了一天了都


    2012年5月11日 6:58