繁体   English   中英

.Net Core T4 运行转换无法加载文件或程序集

[英].Net Core T4 Running transformation could not load file or assembly

我有一个 .Net Core Asp.Net MVC 应用程序,我正在尝试创建一个 T4 文件,该文件使用反射列出控制器的所有方法。 但是,在引用 Controller 类时会引发错误。 我尝试添加 Mvc.Core NuGet 包,但最新版本是 2.2.5,出于某种原因,它期待 v3.1.0.0。

Error       Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at Microsoft.VisualStudio.TextTemplating5EB735DC155C701BA88F9010B0EBAB3638F86E339180B5A3766CEE0DDDB7B870EC569C6473D06A892E38A012E5B34C56690737513ADB101F2235F88AEABE2E1D.GeneratedTextTransformation.TransformText()
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at CallSite.Target(Closure , CallSite , Object )
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.PerformTransformation()

这是我的 tt 文件:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ template language="C#v3.1" #>
<#@ assembly name="System.Core" #>
<#@ output extension=".cs" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Reflection" #>
class Foo {
    <# Assembly asm = Assembly.GetAssembly(typeof(UserController)); #>
}

您不能直接在 T4 模板中引用程序集类。 如果您想使用解决方案的程序集访问路径,您可以使用 Host 类File.ReadAllText(this.Host.ResolvePath("Him.txt"));

<#@ assembly name="$(SolutionDir)YourProject\bin\Debug\Project.Name.dll" #>

您可以访问在导入的程序集中定义的类,棘手的是将内部类公开给您的 T4 模板。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM