因此,我有一个T4模板正在尝试在设计时运行,但是它一直给我以下错误.
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'我的Visual Studios解决方案中包含10个项目,所有这些项目都针对.Net Core 2.0框架.我的T4模板目前看起来像这样:
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(); #> }目前,我只需要模板中引用的程序集即可,该程序集是.Net Core 2.0类库项目.我尝试在此特定的库中添加System.Runtime.dll引用,但似乎没有任何区别.
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.
我已经阅读了其他一些与此类似的问题,通常看来.Net Core似乎与T4模板有关,但是似乎大多数人的解决方案都针对.Net标准库.我不确定这是否适合我,因为我的整个解决方案仅涉及.Net Core项目.
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.
编辑
我将我的所有项目都更改为.Net Standard 2.0而不是.Net Core,并且解决了最初的问题,但是现在我看到了此错误:
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()推荐答案
我找到了System.Runtime dll错误的解决方法.
I found a workaround for the System.Runtime dll error.
将此bindingRedirect放入<configuration>-> <runtime>-> <assemblyBinding>内的C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\15.0_29f8d23a\devenv.exe.config内,其他所有bindingRedirect的
Put this bindingRedirect inside the C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\15.0_29f8d23a\devenv.exe.config inside <configuration> -> <runtime> -> <assemblyBinding> where are all the others bindingRedirect's
<dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/> </dependentAssembly>这是Visual Studio或T4模板引擎中的错误: developercommunity.visualstudio/content/problem/358905/filenotfoundexception-systemruntime-version4210-wh.html
It's a bug in Visual Studio or T4 Template Engine: developercommunity.visualstudio/content/problem/358905/filenotfoundexception-systemruntime-version4210-wh.html
更多推荐
T4模板无法加载文件或程序集"System.Runtime,版本= 4.2.0.0"
发布评论