Ner*_*roS 5 .net c# debugging t4 json.net
我在这里遇到了一些麻烦 - 当我保存或"运行自定义工具"时,应该生成C#类的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
Run Code Online (Sandbox Code Playgroud)
这显然与Json.Net有关.我认为问题可能出在Json.Net软件包中,可能是版本之间存在差异 - 但解决方案中的所有项目都使用完全相同的版本.
为了记录,JsonClassGenerator就是这个文件:http://jsonclassgenerator.codeplex.com/SourceControl/latest#JsonCSharpClassGeneratorLib/JsonClassGenerator.cs
第82行是
GenerateClass(examples, rootType);
Run Code Online (Sandbox Code Playgroud)
好的解决方案是......调试.但是,我无法调试那些......好吧,在调试时拒绝bug.在这方面,我似乎已经筋疲力尽,任何想法都可以尝试?当然,模板工作正常,但每次我想通过右键单击 - >调试更新它们时必须运行它们?似乎没有按预期工作.
编辑:
<#@ 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)#>
<#}#>
<#}#>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1065 次 |
| 最近记录: |