I have a .Net Core Asp.Net MVC app and I am trying to create a T4 file that uses reflection to list all methods of a controller. However, when referencing the Controller class it throws an error. I tried adding the Mvc.Core NuGet package, but the latest version is 2.2.5, and for some reason it's expecting 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()
This is my tt file:
<#@ 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)); #>
}
You can't refer assembly classes in T4 template directly. if you want to access the path using assembly of the solution you can use the Host class File.ReadAllText(this.Host.ResolvePath("Him.txt"));
<#@ assembly name="$(SolutionDir)YourProject\bin\Debug\Project.Name.dll" #>
您可以访问在导入的程序集中定义的类,棘手的是将内部类公开给您的 T4 模板。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.