I had previously been having issues getting reflection to work properly in T4 Templates targeting the .Net Core
framework. I resolved that through the answer on my previous thread, which may be important as the binding redirect may have some impact on my current issue. T4 Template Could not load file or assembly 'System.Runtime, Version = 4.2.0.0'
I managed to get the templates to generate properly, but only if they were referencing assemblies other than their own. Now I have a case where I have a T4 Template referencing the assembly/project the file is currently located in, and am getting this error: System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
My template code is as follows:
<#@ 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();
#>
}
As a reminder, I am forcibly using System.Runtime version 4.0.0.0
since that seems to be the only that to work properly for T4 Templates targeting .Net Core frameworks. Is there something similar I can do to point to the System.Runtime.CompilerServices
namespace?
Aucun commentaire:
Enregistrer un commentaire