Building VB Applications Using vbc.exe

Both VB and C# provide a raw command line compiler.  These command line compilers are included with the
free .NET SDK and Visual Studio.  Although we will be using Visual Studio throughout the course, it is
instructive to learn how to use the command line compilers.

The VB compiler (vbc.exe) and the C# compiler (csc.exe) have many shared options. For example, assume we
have the following VB source code, authored with a simple text editor.  Notice the extension of this file is *.vb.  
Under the .NET platform, all VB code is entered in *.vb files.  Older VB 6.0 file extensions (*.bas, *.frm, *.cls)
are not used.  Don’t worry about any unfamiliar syntax yet!   For now, we just want to focus on the mechanics
of building a VB application with vbc.exe.

















First, get to know the core options of the VB compiler. The first task is to specify the type of binary to build:
Console application, DLL, Windows application, and so forth.

Each of these choices has a corresponding compiler option:




























To compile the FirstApp.vb file into a console application, use the following command:


vbc /target:exe FirstApp.vb


To run the program, simply enter the name of the executable and press Enter.












Of course, you can also compile multiple source files into one assembly, as the following examples shows:


vbc /target:exe FirstApp.vb MoreCode.vb EvenMoreCode.vb Etc.vb


Or you can compile all *.vb files in the directory:


vbc /target:exe *.vb


To compile a DLL, you use the /target:library option. For example, consider the following FirstClass.vb file:















The following command compiles this into FirstLibrary.dll:


vbc /target:library /out:FirstLibrary.dll FirstClass.vb


Now try to use the FirstLibrary.dll from your main application. First, modify the Main code to create a
MyFirstClass object, and call the SayHello method:



















Second, recompile using the
/reference option to reference the FirstLibrary.dll. This allows the compiler to
resolve the MyFirstClass type:


vbc /target:exe /reference:FirstLibrary.dll FirstApp.vb


Here is the result:
Copyright (c) 2008.  Intertech, Inc. All Rights Reserved.  This information is to be used exclusively as an
online learning aid.  Any attempts to copy, reproduce, or use for training is strictly prohibited.
Building VB Applications Using vbc.exe
Table of Contents

 
Compiler Option


Meaning in Life

/out

Use to specify the name of the output file (e.g., MyAssembly.dll,
WordProcessingApp.exe, etc.).  

By default, the name of the output file will be the same as the
name as the input *.vb file, and thus the /out flag can be omitted.

/target:exe

Builds an EXE console application (e.g., a DOS application). This
is the default file output type and thus may be omitted.

/target:library

Builds a DLL assembly with a related manifest.

 /target:module

 Builds a module. This is a partial DLL that does not contain a
 manifest and must therefore be associated with a multifile
 assembly.

/target:winexe

 Builds an executable Windows application.  
Training Resources
Tutorials
Courseware
Services