-platform (Visual Basic)-platform (Visual Basic)

指定公共语言运行时 (CLR) 的哪个平台版本可以运行输出文件。Specifies which platform version of common language runtime (CLR) can run the output file.

语法Syntax

-platform:{ x86 | x64 | Itanium | arm | anycpu | anycpu32bitpreferred }  

自变量Arguments

术语Term 定义Definition
x86 将程序集编译成可由 32 位、x86 可兼容 CLR 运行。Compiles your assembly to be run by the 32-bit, x86-compatible CLR.
x64 将程序集编译成可由支持 AMD64 或 EM64T 指令集的计算机上的 64 位 CLR 运行。Compiles your assembly to be run by the 64-bit CLR on a computer that supports the AMD64 or EM64T instruction set.
Itanium 将程序集编译成可由配有 Itanium 处理器的计算机上的 64 位 CLR 运行。Compiles your assembly to be run by the 64-bit CLR on a computer with an Itanium processor.
arm 将程序集编译成可在配有高级 RISC 计算机 (ARM) 处理器的计算机上运行。Compiles your assembly to be run on a computer with an ARM (Advanced RISC Machine) processor.
anycpu 将程序集编译成可在任意平台上运行。Compiles your assembly to run on any platform. 应用程序将作为 32 位应用程序在 Windows 的 32 位版本上运行,作为 64 位应用程序在 Windows 的 64 位版本上运行。The application will run as a 32-bit application on 32-bit versions of Windows and as a 64-bit application on 64-bit versions of Windows. 此标志为默认值。This flag is the default value.
anycpu32bitpreferred 将程序集编译成可在任意平台上运行。Compiles your assembly to run on any platform. 应用程序将作为 32 位 应用程序在 Windows 的 32 位版本和 64 位版本上运行。The application will run as a 32-bit application on both 32-bit and 64-bit versions of Windows. 此标志仅对可执行文件 (.EXE) 有效且需要 .NET Framework 4.5。This flag is valid only for executables (.EXE) and requires .NET Framework 4.5.

备注Remarks

使用 -platform 选项来指定输出文件所面向的处理器类型。Use the -platform option to specify the type of processor targeted by the output file.

通常,无论平台如何,Visual Basic 内编写的 .NET Framework 程序集将运行相同内容。In general, .NET Framework assemblies written in Visual Basic will run the same regardless of the platform. 但是,存在一些不同平台行为不同的情况。However, there are some cases that behave differently on different platforms. 这些常见的情况是:These common cases are:

  • 结构中包含大小随平台而改变的成员,如任何指针类型。Structures that contain members that change size depending on the platform, such as any pointer type.

  • 指针算术包含固定大小。Pointer arithmetic that includes constant sizes.

  • 平台调用错误,或使用句柄的 Integer 而非 IntPtr 的 COM 声明不正确。Incorrect platform invoke or COM declarations that use Integer for handles instead of IntPtr.

  • IntPtr 强制转换为 IntegerCasting IntPtr to Integer.

  • 将平台调用或 COM 互操作与不存在于任何平台的组件一起使用。Using platform invoke or COM interop with components that do not exist on all platforms.

如果你知道你对将运行代码的体系结构进行了假定,则可使用 -platform 选项减少一些问题。The -platform option will mitigate some issues if you know you have made assumptions about the architecture your code will run on. 尤其是在下列情况下:Specifically:

  • 如果你针对 64 位平台且应用程序在 32 位计算机上运行,则相对于不使用此开关而出现的错误,此错误消息更早出现且更加针对问题。If you decide to target a 64-bit platform, and the application is run on a 32-bit machine, the error message comes much earlier and is more targeted at the problem than the error that occurs without using this switch.

  • 如果你在选项上设置 x86 标志且之后应用程序在 64 位计算机上运行,则应用程序将在 WOW 子系统中运行而不是在本机上运行。If you set the x86 flag on the option and the application is subsequently run on a 64-bit machine, the application will run in the WOW subsystem instead of running natively.

在 64 位 Windows 操作系统上:On a 64-bit Windows operating system:

  • -platform:x86 编译的程序集将在 WOW64 下运行的 32 位 CLR 上执行。Assemblies compiled with -platform:x86 will execute on the 32-bit CLR running under WOW64.

  • -platform:anycpu 编译的可执行文件将在 64 位 CLR 上执行。Executables compiled with the -platform:anycpu will execute on the 64-bit CLR.

  • -platform:anycpu 编译的 DLL 将在加载它的进程所在的同一 CLR 上执行。A DLL compiled with the -platform:anycpu will execute on the same CLR as the process into which it loaded.

  • -platform:anycpu32bitpreferred 编译的可执行文件将在 32 位 CLR 上执行。Executables that are compiled with -platform:anycpu32bitpreferred will execute on the 32-bit CLR.

有关如何开发要在 Windows 的 64 位版本上运行的应用程序的详细信息,请参阅 64 位应用程序For more information about how to develop an application to run on a 64-bit version of Windows, see 64-bit Applications.

若要在 Visual Studio IDE 中设置 -platformTo set -platform in the Visual Studio IDE

  1. 在“解决方案资源管理器”中,选择项目,打开“项目”菜单,然后单击“属性” 。In Solution Explorer, choose the project, open the Project menu, and then click Properties.

  2. 在“编译”选项卡上,选择或清除“首选 32 位”复选框,或者在“目标 CPU”列表中,选择一个值 。On the Compile tab, select or clear the Prefer 32-bit check box, or, in the Target CPU list, choose a value.

    有关详细信息,请参阅编译页 (Visual Basic)For more information, see Compile Page, Project Designer (Visual Basic).

示例Example

下例阐释使用 -platform 编译器选项的方式。The following example illustrates how to use the -platform compiler option.

vbc -platform:x86 myFile.vb  

请参阅See also