2013-11-24 37 views
4

我在這裏遇到了一些麻煩 - 我應該生成C#類的T4模板在保存或「運行自定義工具」時拒絕成功運行。但是 - 這隻有當我「調試T4模板」,它運行成功沒有錯誤。T4模板只在我「調試」它們時運行

的錯誤如下:

Error 1 Running transformation: System.MissingMethodException: Method not found: 'System.Collections.Generic.IEnumerator`1<Newtonsoft.Json.Linq.JToken> Newtonsoft.Json.Linq.JArray.GetEnumerator()'. 
    at JsonCSharpClassGenerator.JsonClassGenerator.GenerateClass(JObject[] examples, JsonType type) 
    at JsonCSharpClassGenerator.JsonClassGenerator.GenerateClasses() in c:\Users\Nero\Documents\Visual Studio 2013\Projects\BluePOCO\JsonCSharpClassGenerator\JsonClassGenerator.cs:line 82 
    at ApiTransformer.ClassGenerator.Generate(String json, String className) in c:\Users\Nero\Documents\Visual Studio 2013\Projects\BluePOCO\ApiTransformer\ClassGenerator.cs:line 25 
    at Microsoft.VisualStudio.TextTemplatingDCEBAFBE8B1AF87B73F34AE53B7F0A1037491F7FD56EC9906754016DE7399CD0992B239FF4A836115489D16A9EE78F6DCBA10BE4137758F32395F1DB7ADF7FF1.GeneratedTextTransformation.TransformText() C:\Users\Nero\documents\visual studio 2013\Projects\BluePOCO\BluePOCO\BlueprintTransformer.tt 1 1 BluePOCO 

這顯然是與Json.Net。我認爲這個問題可能出現在Json.Net包中,可能是版本之間的差異 - 但解決方案中的所有項目都使用完全相同的版本。

爲了記錄在案,JsonClassGenerator是這樣的文件: http://jsonclassgenerator.codeplex.com/SourceControl/latest#JsonCSharpClassGeneratorLib/JsonClassGenerator.cs

82號線是

GenerateClass(examples, rootType); 

的obious的解決辦法是...調試。但是,我無法調試那些...以及在調試時拒絕錯誤。我似乎已經精疲力盡了我的大腦,我有什麼想法可以嘗試?當然,模板工作正常,但每次我想通過右鍵單擊更新來運行它們 - >調試?似乎沒有按預期工作。

編輯:

<#@ template debug="false" hostspecific="true" language="C#" #> 
<#@ assembly name="System.Core" #> 
<#@ assembly name="System.Windows.Forms" #> 
<#@ assembly name="$(SolutionDir)\BluePOCO\bin\Debug\ApiTransformer.dll" #> 
<#@ assembly name="$(SolutionDir)BluePOCO\bin\Debug\RestSharp.dll"#> 
<#@ import namespace="ApiTransformer"#> 
<#@ import namespace="System.Collections" #> 
<#@ import namespace="System.IO" #> 
<#@ import namespace="System" #> 
<#@ import namespace="System.Linq" #> 
<#@ import namespace="System.Text" #> 
<#@ import namespace="System.Net"#> 
<#@ import namespace="System.Collections.Generic" #> 
<#@ import namespace="System.Reflection" #> 
<#@ import namespace="RestSharp"#> 
<#@ output extension=".cs" #> 
<# 
var filename = "Source.txt"; 
var filepath = Path.Combine(Path.GetDirectoryName(this.Host.ResolvePath("")), "BluePOCO", filename); 
var list = Transformer.GetMethodList(File.ReadAllText(filepath)); 
string str; 
#> 
using System.ComponentModel; 
using Restcoration; 
using RestSharp; 
using Newtonsoft.Json; 
namespace BluePOCO 
{ <#foreach(var item in list){#> 
<# str = item.Resource.Length > 1 ? string.Join("", item.Resource.Split('/').Select(x => x.Length > 0 ? x.Substring(0, 1).ToUpper() + x.Substring(1) : "")) : "Root";#> 

<# 
    var methodList = new List<string>(); 
    foreach(var response in item.Responses) 
    { 
     methodList.Add(string.Format("{0} = typeof({1})", Enum.GetName(typeof (HttpStatusCode), int.Parse(response.Code)), str + response.Code)); 
    } 
    string add; 
    if(methodList.Any()) 
     add = ", " + string.Join(", ", methodList); 
    else 
     add = ""; 
#> 

[Rest(Method = Method.<#=item.Method#><#=add#>)]<#foreach(var response in item.Responses){#> 

<#=ClassGenerator.Generate(response.Json, str+response.Code)#> 

<#}#> 
<#}#> 

} 

回答

0

嘗試

<#@模板調試= 「真」

+0

可悲沒有幫助:( – NeroS

0

我有同樣的問題時,我的項目使用舊Newtonsoft.Json.dll V4 .5.11.15520。

我更換使用最新版本的Newtonsoft.Json.dll後,問題就消失了。 v8.0.3.19514