How to specify that T4 template should be transformed using x64 platform?

1

I am trying to create a C++ wrapper for a .NET library called SEI (link, file USDDeviceExplorer_x64_1.zip). To do that, I am writing a T4 template which references USDSEI.dll assembly like this:

<#@ assembly name="$(SolutionDir)..\USDDeviceExplorer_x64_1\USDigital.dll" #>
<#@ assembly name="$(SolutionDir)..\USDDeviceExplorer_x64_1\AGauge.dll" #>
<#@ assembly name="$(SolutionDir)..\USDDeviceExplorer_x64_1\USDSEI.dll" #>

But template is not getting transformed (the complete error message below). Referencing the exact same assembly from normal C# code compiles normally. I am compiling everything as x64 platform. When my C# project had AnyCPU platform it refused to build with the same error message.

Is there a way to specify that T4 template should be "executed" using x64 platform? I think that by some default it uses AnyCPU platform and that causes transformation to fail.

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   
c#
.net-4.0
t4
asked on Stack Overflow Jul 27, 2018 by Dženan • edited Jul 27, 2018 by Dženan

1 Answer

0

Another question states that T4 template is executed as 32-bit process because Visual Studio is a 32-bit executable. Fortunately, an answer there offers Assembly.ReflectionOnlyLoad() as a possible alternative.

answered on Stack Overflow Jul 31, 2018 by Dženan

User contributions licensed under CC BY-SA 3.0