如何加载特定版本的程序集

时间:2022-08-15 22:57:48

To complete some testing I need to load the 64 bit version of an assembly even though I am running a 32 bit version of Windows. Is this possible?

要完成一些测试,我需要加载64位版本的程序集,即使我运行的是32位版本的Windows。这可能吗?

4 个解决方案

#1


4  

I'm not sure why you would want to do this, but I suppose you could. If you don't do anything to tell it otherwise, the CLR will load the version of the assembly that is specific to the CPU you are using. That's usually what you want. But I have had an occasion where I needed to load the neutral IL version of an assembly. I used the Load method to specify the version. I haven't tried it (and others here suggest it won't work for an executable assembly), but I suppose you can do the same to specify you want to load the 64 bit version. (You'll have to specify if you want the AMD64 or IA64 version.)

我不确定你为什么要这样做,但我想你可以。如果您不做任何其他事情,CLR将加载特定于您正在使用的CPU的程序集版本。这通常是你想要的。但我有一个机会,我需要加载中立的IL版本的程序集。我使用Load方法指定版本。我没有尝试过(其他人建议它不适用于可执行程序集),但我想你也可以这样做来指定你想要加载64位版本。 (您必须指定是否需要AMD64或IA64版本。)

#2


1  

From CLR Via C# (Jeff Richter):

来自CLR Via C#(Jeff Richter):

"If your assembly files contain only type-safe managed code, you are writing code that should work on both 32-bit and 64-bit versions of Windows. No source code changes are required for your code to run on either version of Windows.

“如果您的程序集文件只包含类型安全的托管代码,那么您编写的代码应该适用于32位和64位版本的Windows。无需更改源代码即可在任一版本的Windows上运行代码。

In fact, the resulting EXE/DLL file produced by the compiler will run on 32-bit Windows as well as the x64 and IA64 versions of 64-bit Windows! In other words, the one file will run on any machine that has a version of the .NET Framework installed on it."

实际上,编译器生成的EXE / DLL文件将在32位Windows以及64位Windows的x64和IA64版本上运行!换句话说,一个文件将在任何安装了.NET Framework版本的计算机上运行。“

" The C# compiler offers a /platform command-line switch. This switch allows you to specify whether the resulting assembly can run on x86 machines running 32-bit Windows versions only, x64 machines running 64-bit Windows only, or Intel Itanium machines running 64-bit Windows only. If you don't specify a platform, the default is anycpu, which indicates that the resulting assembly can run on any version of Windows.

“C#编译器提供/ platform命令行开关。此开关允许您指定生成的程序集是否可以在仅运行32位Windows版本的x86计算机上运行,​​仅运行64位Windows的x64计算机或运行的Intel Itanium计算机仅限64位Windows。如果未指定平台,则默认为anycpu,表示生成的程序集可以在任何版本的Windows上运行。

#3


-1  

32 bit Windows can not run 64 bit executables without a VM/emutalor

没有VM / emutalor,32位Windows无法运行64位可执行文件

32 bit Windows can compile for execution on 64 bit Windows

32位Windows可以在64位Windows上编译执行

#4


-1  

No, you cannot run assemblies that are compiled for 64-bit on a system running the 32-bit version of Windows.

不,您无法在运行32位版本Windows的系统上运行为64位编译的程序集。

#1


4  

I'm not sure why you would want to do this, but I suppose you could. If you don't do anything to tell it otherwise, the CLR will load the version of the assembly that is specific to the CPU you are using. That's usually what you want. But I have had an occasion where I needed to load the neutral IL version of an assembly. I used the Load method to specify the version. I haven't tried it (and others here suggest it won't work for an executable assembly), but I suppose you can do the same to specify you want to load the 64 bit version. (You'll have to specify if you want the AMD64 or IA64 version.)

我不确定你为什么要这样做,但我想你可以。如果您不做任何其他事情,CLR将加载特定于您正在使用的CPU的程序集版本。这通常是你想要的。但我有一个机会,我需要加载中立的IL版本的程序集。我使用Load方法指定版本。我没有尝试过(其他人建议它不适用于可执行程序集),但我想你也可以这样做来指定你想要加载64位版本。 (您必须指定是否需要AMD64或IA64版本。)

#2


1  

From CLR Via C# (Jeff Richter):

来自CLR Via C#(Jeff Richter):

"If your assembly files contain only type-safe managed code, you are writing code that should work on both 32-bit and 64-bit versions of Windows. No source code changes are required for your code to run on either version of Windows.

“如果您的程序集文件只包含类型安全的托管代码,那么您编写的代码应该适用于32位和64位版本的Windows。无需更改源代码即可在任一版本的Windows上运行代码。

In fact, the resulting EXE/DLL file produced by the compiler will run on 32-bit Windows as well as the x64 and IA64 versions of 64-bit Windows! In other words, the one file will run on any machine that has a version of the .NET Framework installed on it."

实际上,编译器生成的EXE / DLL文件将在32位Windows以及64位Windows的x64和IA64版本上运行!换句话说,一个文件将在任何安装了.NET Framework版本的计算机上运行。“

" The C# compiler offers a /platform command-line switch. This switch allows you to specify whether the resulting assembly can run on x86 machines running 32-bit Windows versions only, x64 machines running 64-bit Windows only, or Intel Itanium machines running 64-bit Windows only. If you don't specify a platform, the default is anycpu, which indicates that the resulting assembly can run on any version of Windows.

“C#编译器提供/ platform命令行开关。此开关允许您指定生成的程序集是否可以在仅运行32位Windows版本的x86计算机上运行,​​仅运行64位Windows的x64计算机或运行的Intel Itanium计算机仅限64位Windows。如果未指定平台,则默认为anycpu,表示生成的程序集可以在任何版本的Windows上运行。

#3


-1  

32 bit Windows can not run 64 bit executables without a VM/emutalor

没有VM / emutalor,32位Windows无法运行64位可执行文件

32 bit Windows can compile for execution on 64 bit Windows

32位Windows可以在64位Windows上编译执行

#4


-1  

No, you cannot run assemblies that are compiled for 64-bit on a system running the 32-bit version of Windows.

不,您无法在运行32位版本Windows的系统上运行为64位编译的程序集。