我以前一直遇到问题,无法在针对.Net Core
框架的T4模板中正常工作。我通过上一个线程的答案解决了这个问题,这可能很重要,因为绑定重定向可能会对我当前的问题产生一些影响。
T4 Template Could not load file or assembly 'System.Runtime, Version = 4.2.0.0'
我设法使模板正确生成,但前提是它们引用的不是自己的程序集。现在,我有一个T4模板,该模板引用文件当前所在的程序集/项目,并出现此错误:
System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
我的模板代码如下:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Reflection" #>
<#@ assembly name="$(TargetDir)Services.dll" #>
<#@ assembly name="$(NuGetPackageRoot)\automapper\8.0.0\lib\netstandard2.0\AutoMapper.dll" #>
<#@ import namespace="Services" #>
<#@ import namespace="Services.Resources.Attributes" #>
<#@ import namespace="Services.Resources.DataTransferObjects.Infrastructure" #>
<#@ output extension=".cs" #>
//Autogen code
//This code is autogen. Do not make any changes to this file
namespace Services
{
<#
var classes = System.Reflection.Assembly.GetAssembly(typeof(BaseService))
.GetTypes()
.Where(p => !p.IsAbstract && p.BaseType == typeof(BaseService))
.ToList();
#>
}
提醒一下,我正在强制使用System.Runtime version 4.0.0.0
,因为这似乎是唯一可针对目标为.Net Core框架的T4模板正常工作的工具。我可以做些类似的事情来指向System.Runtime.CompilerServices
命名空间吗?