簡體   English   中英

T4 模板無法加載文件或程序集“System.Runtime,版本 = 4.2.0.0”

[英]T4 Template Could not load file or assembly 'System.Runtime, Version = 4.2.0.0'

所以我有一個 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 Standard 庫的。 我不確定這是否適用於我,因為我的整個解決方案只涉及 .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()

我找到了System.Runtime dll 錯誤的解決方法。

將此 bindingRedirect 放在C:\\Users\\<user>\\AppData\\Local\\Microsoft\\VisualStudio\\15.0_29f8d23a\\devenv.exe.config<configuration> -> <runtime> -> <assemblyBinding>其他所有 bindingRedirect 的位置

<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 模板引擎中的錯誤: https : //developercommunity.visualstudio.com/content/problem/358905/filenotfoundexception-systemruntime-version4210-wh.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM