So I have a T4 Template I'm trying to run at design-time, but it keeps giving me the following error.
Running transformation: System.IO.FileNotFoundException: Could not load
file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system
cannot find the file specified.
File name: 'System.Runtime, Version=4.2.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
My Visual Studios solution has 10 projects contained within it, all of which target .Net Core 2.0 framework. My T4 template presently looks as such:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="Services.Resources.DataTransferObjects.Infrastructures" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ assembly name="$(TargetDir)Services.dll" #>
<#@ output extension=".cs" #>
public class AdminDTO
{
<#var editableObjs = Assembly
.GetAssembly(typeof(GenericEditable<>))
.GetTypes()
.Where(p => p.BaseType != null && p.BaseType.IsGenericType && p.BaseType.GetGenericTypeDefinition() == (typeof(GenericEditable<>)))
.ToList();
#>
}
At the moment I only need the assembly I've referenced in the template, which is a .Net Core 2.0 class library project. I've tried adding the System.Runtime.dll reference in this particular library, but it doesn't appear to make any difference.
I've read several other issues similar to this, and it generally seems that .Net Core seems to have issues with T4 Templates, but it appeared most peoples' solutions were to target a .Net Standard library. I'm not sure this is applicable for me, as my entire solution only involves .Net Core projects.
EDIT
I changed all my projects to target .Net Standard 2.0 instead of .Net Core, and that fixed my initial problem, but now I see this error:
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()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…