微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

T4模板当我升级到.Net 4.8时,程序集加载停止运行

如何解决T4模板当我升级到.Net 4.8时,程序集加载停止运行

我有一个T4模板,当我的项目使用.Net 4.6.2时,模板正在运行。我正在使用Visual Studio 2019。

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(SolutionDir)MyProject\bin\x64\Debug\MyProject.FooBar.dll" #>
<#@ output extension=".cs" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Reflection" #>

升级到.Net 4.8的整个解决方案后,尝试运行模板时出现以下错误

Severity    Code    Description Project File    Line    Suppression State
Error       There was a problem loading the assembly     'C:\Repos\MyProject\bin\x64\Debug\MyProject.FooBar.dll' The following Exception was thrown:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Repos\MyProject\bin\x64\Debug\MyProject.FooBar.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\Repos\MyProject\bin\x64\Debug\MyProject.FooBar.dll'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,String codeBase,Evidence assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark& stackMark,IntPtr pPrivHostBinder,Boolean throwOnFileNotFound,Boolean forIntrospection,Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName,Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,RuntimeAssembly reqAssembly,Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile,Evidence securityEvidence,Byte[] hashValue,AssemblyHashAlgorithm hashAlgorithm,Boolean suppressSecurityChecks,StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.AttemptAssemblyLoad(String assemblyName)

=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\Repos\MyProject\bin\x64\Debug\MyProject.FooBar.dll
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/Common7/IDE/
LOG: Initial PrivatePath = NULL
Calling assembly : (UnkNown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context,like with Assembly.Load().
LOG: Using application configuration file: C:\Users\ptaylor\AppData\Local\Microsoft\VisualStudio\16.0_9613a24e\devenv.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Repos/MyProject\bin\x64\Debug\MyProject.FooBar.dll.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.            1   

过去,我环顾四周,发现了一些类似的问题,但是修复程序使用的是完全限定的名称(检查),或者尝试使用此修复程序T4 Template Could not load file or assembly 'System.Runtime,Version = 4.2.0.0',但我尝试无济于事。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。