TypeLite 全新安装不起作用

Jos*_*osh 5 typelite

我刚刚通过 NuGet 将 TypeLite 安装到我的项目中,但它不起作用,我尝试过的一切都没有帮助......这是安装后创建的文件:

<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="$(TargetDir)TypeLite.dll" #>
<#@ assembly name="$(TargetDir)TypeLite.Net4.dll" #>
<#@ assembly name="$(TargetDir)$(TargetFileName)" #>

<#@ import namespace="TypeLite" #> 
<#@ import namespace="TypeLite.Net4" #> 
<#@output extension=".d.ts"#>

 <#@include file="Manager.ttinclude"#>
<# var manager = Manager.Create(Host, GenerationEnvironment); #>

<# var ts = TypeScript.Definitions()
        .WithReference("Enums.ts")
        .ForLoadedAssemblies();
#>

<#= ts.Generate(TsGeneratorOutput.Properties) #>

<# manager.StartNewFile("Enums.ts"); #>
<#= ts.Generate(TsGeneratorOutput.Enums) #>
<# manager.EndBlock(); #>
<# manager.Process(true); #>
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

Severity    Code    Description Project File    Line
Error       Running transformation: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at TypeLite.TsModelBuilder.Add(Assembly assembly)
   at TypeLite.Net4.TypeScriptFluentExtensions.ForLoadedAssemblies(TypeScriptFluent ts)
   at Microsoft.VisualStudio.TextTemplating097C215A707CB07DE5AACDA590F263DF8554A0CCA899B583BF1832F7C0C5D3E595312AE41D3DFD1BB9CA643458AA5D86FE3DBA281ED0000D4B4C1D87EA1DEFFB.GeneratedTextTransformation.TransformText() MyApp   S:\MyApp\Scripts\TypeLite.Net4.tt   1
Run Code Online (Sandbox Code Playgroud)

如果我选择“调试 T4 模板”,这就是我得到的:

Severity    Code    Description Project File    Line
Error       Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
       at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
   at TypeLite.Extensions.TypeExtensions.GetCustomAttribute[TType](Type type, Boolean inherit)
   at TypeLite.TsModelBuilder.<Add>b__4(Type t)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at TypeLite.TsModelBuilder.Add(Assembly assembly)
   at TypeLite.Net4.TypeScriptFluentExtensions.ForLoadedAssemblies(TypeScriptFluent ts)
   at Microsoft.VisualStudio.TextTemplating097C215A707CB07DE5AACDA590F263DF8554A0CCA899B583BF1832F7C0C5D3E595312AE41D3DFD1BB9CA643458AA5D86FE3DBA281ED0000D4B4C1D87EA1DEFFB.GeneratedTextTransformation.TransformText() in s:\MyApp\Scripts\TypeLite.Net4.tt:line 13

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : Breeze.WebApi2, Version=1.5.0.0, Culture=neutral, PublicKeyToken=f6085f1a45e2ac59.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http/System.Web.Http.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/System.Web.Http/System.Web.Http.EXE.
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http/System.Web.Http.DLL.
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http.EXE.
LOG: Attempting download of new URL file:///S:/MyApp/bin/System.Web.Http/System.Web.Http.EXE.   MyApp   s:\MyApp\Scripts\TypeLite.Net4.tt   13
Run Code Online (Sandbox Code Playgroud)

如果我将其添加到文件中:

<#@ 程序集名称="System.Web.Http.dll" #>

然后我得到:

Error       Compiling transformation: Assembly 'WebUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'    MyApp   S:\MyASpp\Scripts\TypeLite.Net4.tt  1
Run Code Online (Sandbox Code Playgroud)

不幸的是,我一直无法弄清楚 5.2.2 参考在哪里;我的项目中的所有内容都是 5.2.3。如果我将文件路径带到我的 5.2.3 DLL 并将其放入(来自 nuget 的 c:\packages...),它就可以工作。

我想我的问题是为什么它没有通过项目找到 DLL 引用,或者有更好的方法来做到这一点?我不想在这个文件中硬编码路径,理想情况下我根本不需要指定它们,但此时我不知道如何做。

Luk*_*brt 0

T4 模板对项目中安装的包一无所知,因此有必要手动添加对使用的程序集的引用。

显然 T4 正在尝试加载错误版本的库。我会检查您的bin文件夹是否包含正确版本的程序集,并尝试从那里引用该库。

<#@ assembly name="$(TargetDir)System.Web.Http.dll" #>
Run Code Online (Sandbox Code Playgroud)