示例编译命令行 (Visual Basic)Sample compilation command lines (Visual Basic)

作为从 Visual Studio 中编译 Visual Basic 程序的替代方法,可以从命令行进行编译,以生成可执行 (.exe) 文件或动态链接库 (.dll) 文件。As an alternative to compiling Visual Basic programs from within Visual Studio, you can compile from the command line to produce executable (.exe) files or dynamic-link library (.dll) files.

Visual Basic 命令行编译器支持一组完整的选项,这些选项控制输入和输出文件、程序集以及调试和预处理器选项。The Visual Basic command-line compiler supports a complete set of options that control input and output files, assemblies, and debug and preprocessor options. 每个选项都以两种可互换形式提供:-option/optionEach option is available in two interchangeable forms: -option and /option. 此文档仅显示 -option 形式。This documentation shows only the -option form.

下表列出可以进行修改以供自己使用的一些示例命令行。The following table lists some sample command lines you can modify for your own use.

功能To 使用Use
编译 File.vb 并创建 File.exeCompile File.vb and create File.exe vbc -reference:Microsoft.VisualBasic.dll File.vb
编译 File.vb 并创建 File.dllCompile File.vb and create File.dll vbc -target:library File.vb
编译 File.vb 并创建 My.exeCompile File.vb and create My.exe vbc -out:My.exe File.vb
编译 File.vb 并创建库和名为 File.dll 的引用程序集Compile File.vb and create both a library and a reference assembly named File.dll vbc -target:library -ref:.\debug\bin\ref\file.dll File.vb
编译当前目录中的所有 Visual Basic 文件(打开了优化并定义了 DEBUG 符号),生成 File2.exeCompile all Visual Basic files in the current directory, with optimizations on and the DEBUG symbol defined, producing File2.exe vbc -define:DEBUG=1 -optimize -out:File2.exe *.vb
编译当前目录中的所有 Visual Basic 文件,生成 File2.dll 的调试版本而不显示徽标或警告Compile all Visual Basic files in the current directory, producing a debug version of File2.dll without displaying the logo or warnings vbc -target:library -out:File2.dll -nowarn -nologo -debug *.vb
将当前目录中的所有 Visual Basic 文件编译为 Something.dllCompile all Visual Basic files in the current directory to Something.dll vbc -target:library -out:Something.dll *.vb

提示

使用 Visual Studio IDE 生成项目时,可以在输出窗口中显示有关关联 vbc 命令及其编译器选项的信息。When you build a project by using the Visual Studio IDE, you can display information about the associated vbc command with its compiler options in the output window. 若要显示此信息,请打开“选项”对话框、“项目和解决方案”、“生成和运行”,然后将“MSBuild 项目生成输出详细信息” 设置为“普通” 或更高级别的详细程度。To display this information, open the Options Dialog Box, Projects and Solutions, Build and Run, and then set the MSBuild project build output verbosity to Normal or a higher level of verbosity.

请参阅See also