我正在尝试为名为SEI(link,文件USDDeviceExplorer_x64_1.zip
)的.NET库创建C ++包装器。为此,我正在编写一个T4模板,该模板引用如下的USDSEI.dll
程序集:
<#@ assembly name="$(SolutionDir)..\USDDeviceExplorer_x64_1\USDigital.dll" #>
<#@ assembly name="$(SolutionDir)..\USDDeviceExplorer_x64_1\AGauge.dll" #>
<#@ assembly name="$(SolutionDir)..\USDDeviceExplorer_x64_1\USDSEI.dll" #>
但是模板未转换(下面的完整错误消息)。从普通C#代码引用完全相同的程序集通常会进行编译。我正在将所有内容都编译为x64
平台。当我的C#项目具有AnyCPU
平台时,它拒绝使用相同的错误消息进行构建。
是否有一种方法可以指定应该使用x64
平台“执行” T4模板?我认为默认情况下,它使用AnyCPU
平台,这会导致转换失败。
Severity Code Description Project File Line Suppression State
Error There was a problem loading the assembly 'C:\Dev\PlusGit\Capo64s\PlusLib\Tools\UsDigital\SEI64\..\USDDeviceExplorer_x64_1\USDSEI.dll' The following Exception was thrown:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Dev\PlusGit\Capo64s\PlusLib\Tools\UsDigital\USDDeviceExplorer_x64_1\USDSEI.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\Dev\PlusGit\Capo64s\PlusLib\Tools\UsDigital\USDDeviceExplorer_x64_1\USDSEI.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, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, 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:\Dev\PlusGit\Capo64s\PlusLib\Tools\UsDigital\USDDeviceExplorer_x64_1\USDSEI.dll
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 14.0/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\Dzenan\AppData\Local\Microsoft\VisualStudio\14.0\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:/Dev/PlusGit/Capo64s/PlusLib/Tools/UsDigital/USDDeviceExplorer_x64_1/USDSEI.dll.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated. 1
答案 0 :(得分:0)
另一个question声明T4模板作为32位进程执行,因为Visual Studio是32位可执行文件。幸运的是,那里提供了一个答案Assembly.ReflectionOnlyLoad()
。