-target (Visual Basic)-target (Visual Basic)

指定编译器输出的格式。Specifies the format of compiler output.

语法Syntax

-target:{exe | library | module | winexe | appcontainerexe | winmdobj}

备注Remarks

下表概括了 -target 选项的效果。The following table summarizes the effect of the -target option.

选项Option 行为Behavior
-target:exe 使编译器创建可执行控制台应用程序。Causes the compiler to create an executable console application.

这是未指定任何 -target 选项时的默认选项。This is the default option when no -target option is specified. 将使用 .exe 扩展名创建可执行文件。The executable file is created with an .exe extension.

除非使用 -out 选项进行指定,否则输出文件名采用包含 Sub Main 过程的输入文件的名称。Unless otherwise specified with the -out option, the output file name takes the name of the input file that contains the Sub Main procedure.

编译为 .exe 文件的源代码文件中只需要一个 Sub Main 过程。Only one Sub Main procedure is required in the source-code files that are compiled into an .exe file. 使用 -main 编译器选项可指定包含 Sub Main 过程的类。Use the -main compiler option to specify which class contains the Sub Main procedure.
-target:library 使编译器创建动态链接库 (DLL)。Causes the compiler to create a dynamic-link library (DLL).

将使用 .dll 扩展名创建动态链接库文件。The dynamic-link library file is created with a .dll extension.

除非使用 -out 选项指定,否则输出文件的名称采用第一个输入文件的名称。Unless otherwise specified with the -out option, the output file name takes the name of the first input file.

生成 DLL 时,不需要 Sub Main 过程。When building a DLL, a Sub Main procedure is not required.
-target:module 使编译器生成可添加到程序集的模块。Causes the compiler to generate a module that can be added to an assembly.

将使用扩展名 .netmodule 创建输出文件。The output file is created with an extension of .netmodule.

.NET 公共语言运行时无法加载不包含程序集的文件。The .NET common language runtime cannot load a file that does not have an assembly. 但是,可以使用 -reference 将此类文件合并到程序集的程序集清单中。However, you can incorporate such a file into the assembly manifest of an assembly by using -reference.

如果一个模块中的代码引用另一模块中的内部类型,则两个模块必须使用 -reference 合并到一个程序集清单中。When code in one module references internal types in another module, both modules must be incorporated into an assembly manifest by using -reference.

-addmodule 选项从模块导入元数据。The -addmodule option imports metadata from a module.
-target:winexe 使编译器创建基于 Windows 的可执行应用程序。Causes the compiler to create an executable Windows-based application.

将使用 .exe 扩展名创建可执行文件。The executable file is created with an .exe extension. 基于 Windows 的应用程序从 .NET Framework 类库或使用 Windows API 提供用户界面。A Windows-based application is one that provides a user interface from either the .NET Framework class library or with the Windows APIs.

除非使用 -out 选项进行指定,否则输出文件名采用包含 Sub Main 过程的输入文件的名称。Unless otherwise specified with the -out option, the output file name takes the name of the input file that contains the Sub Main procedure.

编译为 .exe 文件的源代码文件中只需要一个 Sub Main 过程。Only one Sub Main procedure is required in the source-code files that are compiled into an .exe file. 如果代码具有多个附带 Sub Main 过程的类,请使用 -main 编译器选项指定包含 Sub Main 过程的类In cases where your code has more than one class that has a Sub Main procedure, use the -main compiler option to specify which class contains the Sub Main procedure
-target:appcontainerexe 使编译器创建必须在应用容器中运行的基于 Windows 的可执行应用程序。Causes the compiler to create an executable Windows-based application that must be run in an app container. 此设置设计为用于 Windows 8.x 应用商店应用程序。This setting is designed to be used for Windows 8.x Store applications.

appcontainerexe 设置在可移植可执行文件的“特征”字段中设置一个位。The appcontainerexe setting sets a bit in the Characteristics field of the Portable Executable file. 此位只是应用必须在应用容器中运行。This bit indicates that the app must be run in an app container. 设置了该位时,如果 CreateProcess 方法尝试在应用容器外启动应用程序,则会发生错误。When this bit is set, an error occurs if the CreateProcess method tries to launch the application outside of an app container. 除了此位设置外,-target:appcontainerexe 等效于 -target:winexe 。Aside from this bit setting, -target:appcontainerexe is equivalent to -target:winexe.

将使用 .exe 扩展名创建可执行文件。The executable file is created with an .exe extension.

除非使用 -out 选项进行指定,否则输出文件名采用包含 Sub Main 过程的输入文件的名称。Unless you specify otherwise by using the -out option, the output file name takes the name of the input file that contains the Sub Main procedure.

编译为 .exe 文件的源代码文件中只需要一个 Sub Main 过程。Only one Sub Main procedure is required in the source-code files that are compiled into an .exe file. 如果代码包含多个附带 Sub Main 过程的类,请使用 -main 编译器选项指定包含 Sub Main 过程的类If your code contains more than one class that has a Sub Main procedure, use the -main compiler option to specify which class contains the Sub Main procedure
-target:winmdobj 使编译器创建可转换为 Windows 运行时二进制 (.winmd) 文件的中间文件。Causes the compiler to create an intermediate file that you can convert to a Windows Runtime binary (.winmd) file. 除了托管语言程序外,JavaScript 和 C++ 程序也可以使用该 .winmd 文件。The .winmd file can be consumed by JavaScript and C++ programs, in addition to managed language programs.

将使用扩展名 .winmdobj 创建中间文件。The intermediate file is created with a .winmdobj extension.

除非使用 -out 选项进行指定,否则输出文件名采用第一个输入文件的名称。Unless you specify otherwise by using the -out option, the output file name takes the name of the first input file. Sub Main 过程不是必需的。A Sub Main procedure isn’t required.

.winmdobj 文件设计为用作 WinMDExp 导出工具的输入,以生成 Windows 元数据 (WinMD) 文件。The .winmdobj file is designed to be used as input for the WinMDExp export tool to produce a Windows metadata (WinMD) file. WinMD 文件的扩展名为 .winmd,同时包含原始库中的代码以及 JavaScript、C++ 和 Windows 运行时使用的 WinMD 定义。The WinMD file has a .winmd extension and contains both the code from the original library and the WinMD definitions that JavaScript, C++, and the Windows Runtime use.

除非指定 -target:module,否则 -target 会使 .NET Framework 程序集清单添加到输出文件。Unless you specify -target:module, -target causes a .NET Framework assembly manifest to be added to an output file.

每个 Vbc.exe 实例最多生成一个输出文件。Each instance of Vbc.exe produces, at most, one output file. 如果多次指定编译器选项(如 -out-target),则编译器处理的最后一个选项将生效。If you specify a compiler option such as -out or -target more than one time, the last one the compiler processes is put into effect. 有关编译中所有文件的信息会添加到清单中。Information about all files in a compilation is added to the manifest. 除用 -target:module 创建的文件之外,所有输出文件都包含清单中的程序集元数据。All output files except those created with -target:module contain assembly metadata in the manifest. 使用 Ildasm.exe(IL 反汇编程序)可查看输出文件中的元数据。Use Ildasm.exe (IL Disassembler) to view the metadata in an output file.

-target 的缩写形式是 -tThe short form of -target is -t.

若要在 Visual Studio IDE 中设置 -targetTo set -target in the Visual Studio IDE

  1. “解决方案资源管理器” 中选择一个项目。Have a project selected in Solution Explorer. 在“项目”菜单上,单击“属性” 。On the Project menu, click Properties.

  2. 单击“应用程序” 选项卡。Click the Application tab.

  3. 修改“应用程序类型” 框中的值。Modify the value in the Application Type box.

示例Example

以下代码编译 in.vb,从而创建 in.dllThe following code compiles in.vb, creating in.dll:

vbc -target:library in.vb

请参阅See also