免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
引用.net Core類時(shí)T4模板無法加載文件或程序集“ System.Runtime,版本= 4.2.2.0”

用.net Core 編寫的T4模板類, 在T4里引用運(yùn)行時(shí),會(huì)有

錯(cuò)誤        正在運(yùn)行轉(zhuǎn)換: System.IO.FileNotFoundException: 未能加載文件或程序集“System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或它的某一個(gè)依賴項(xiàng)。系統(tǒng)找不到指定的文件。文件名:“System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”   在 Microsoft.VisualStudio.TextTemplatingDF348CB3FB09E8E166E437124F9F88342823FF1D21BC7B73048E47A611D6DC38AD43D38B26E23A35527758646C26C0D989C154CDCD9B21719CC1A062236A2570.GeneratedTextTransformation.TransformText()   在 Microsoft.VisualStudio.TextTemplating.TransformationRunner.PerformTransformation()警告: 程序集綁定日志記錄被關(guān)閉。要啟用程序集綁定失敗日志記錄,請(qǐng)將注冊(cè)表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)設(shè)置為 1。注意: 會(huì)有一些與程序集綁定失敗日志記錄關(guān)聯(lián)的性能損失。要關(guān)閉此功能,請(qǐng)移除注冊(cè)表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。    Ark.Y2020.DBModel    D:\myCode\其他項(xiàng)目\Ark2020\Ark.Y2020.DBModel\BCBenefitConsume.tt    1    

在使用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();        #>}

即使項(xiàng)目引用System.Runtime.dll也是沒有用的, 這個(gè)問題的本質(zhì)是Vs2019工具在運(yùn)行T4程序時(shí)的問題, 所以可以修改Vs相關(guān)的配置才可以

方法一:

參考: https://stackoverflow.com/questions/51550265/t4-template-could-not-load-file-or-assembly-system-runtime-version-4-2-0-0/54314778#54314778

C:\Users\<user>\AppData\Local\Microsoft\VisualStudio\15.0_29f8d23a\devenv.exe.config里有<configuration>-> <runtime>-> <assemblyBinding>

<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>

 

方法二:

上面說了,問題本質(zhì)是Vs的問題, 所以我們不用.net core編寫T4的輔助類即可,使用.net Framework的項(xiàng)目,然后把相關(guān)的Dll復(fù)制到解決方案目錄下

T4的模板如下:

<#@ template debug="Flase" hostspecific="True" language="C#" #><#@ assembly name="$(SolutionDir)T4dll/TC.Ab.T4.dll" #><#@ assembly name="$(SolutionDir)T4dll/MySql.Data.dll" #><#@ import namespace="TC.Ab.T4" #><#@ import namespace="System.Text.RegularExpressions" #><#@ import namespace="System.Diagnostics" #><#@ output extension=".cs" #><#    //Debugger.Launch(); Debugger.Break();//調(diào)試用template debug="True" hostspecific="True" language="C#"    DbField dbRender = new DbField(this.Host.TemplateFile,"TCItravelOrder");//數(shù)據(jù)庫鏈接名稱可以不傳,默認(rèn)MetaDataDB    dbRender.NamespaceStr="TC.itravel.Admin.DBModel";      dbRender.OnlyTable.Add("BCBenefitConsume");//只要生成的表,區(qū)分大小寫    this.WriteLine(dbRender.Render()); #>

 這種情況只是Vs使用了Framework版本的類, 項(xiàng)目本身還是core, 所以不影響項(xiàng)目的發(fā)布,如果是Docker發(fā)布,可以在.dockerignore文件里進(jìn)行排除

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C# Remoting的一個(gè)簡(jiǎn)單例子
快速搞懂.NET 5/.NET Core應(yīng)用程序的發(fā)布部署
ASP.NET 5是如何通過XRE實(shí)現(xiàn)跨平臺(tái)的
.Net core 的熱插拔機(jī)制的深入探索,以及卸載問題求救指南.
T4模版引擎之基礎(chǔ)入門
佐爾
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服