【发布时间】:2018-07-27 03:17:11
【问题描述】:
所以我有一个 T4 模板,我试图在设计时运行,但它一直给我以下错误。
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 模板目前看起来是这样的:
<#@ 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 引用,但它似乎没有任何区别。
我已经阅读了与此类似的其他几个问题,一般看来 .Net Core 似乎与 T4 模板存在问题,但似乎大多数人的解决方案都是针对 .Net 标准库。我不确定这是否适用于我,因为我的整个解决方案只涉及 .Net Core 项目。
编辑
我将我的所有项目都更改为 .Net Standard 2.0 而不是 .Net Core,这解决了我最初的问题,但现在我看到了这个错误:
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()
【问题讨论】:
-
您可以从核心项目中引用 netstandard 项目。
-
好吧,我的都不是网络标准。所以我可以通过努力使它们成为这样,但我不明白为什么也不会有合适的 netcore 解决方案
-
同意应该有办法,但转换项目并不困难或耗时
-
如果是这样,我可能会走这条路。从技术上讲,我的项目中只有 1 个“需要”成为 netcore 项目
-
EF 6 将在 3.0 中移植到 Core
标签: c# visual-studio-2017 asp.net-core-2.0 t4