Section H.1. Compiler Basics


H.1. Compiler Basics

The compiler uses command-line switches to control its operation. A command-line switch is designated by a slash or hyphen, followed by a keyword. If the keyword takes an argument, it is separated from the keyword by a colon (:). For example:

    vbc sample1.vb /target:library 

indicates that the compiler should generate a library (a DLL file) as the output target file type. In this case, target is the switch keyword and library is the argument. If multiple arguments are required, they are usually separated from one another by commas (unless otherwise noted). For example:

    vbc sample1.vb /r:system.design.dll,system.messaging.dll 

references the metadata in the system.design.dll and system.messaging.dll assemblies.

The minimal syntax required to compile a file named sample1.vb is:

    vbc sample1.vb 

This generates a console-mode application named sample1.exe. You can specify the type of component or application you wish to generate by using the /target (or /t) switch. To generate a Windows executable, you enter something like the following at the command line:

    vbc sample1.vb /t:winexe /r:system.windows.forms.dll 

The /r switch adds a reference to the assembly that contains the System.Windows.Forms namespace. You must explicitly add references to any assemblies your application requires, other than mscorlib.dll and microsoft.visualbasic.dll.

To compile multiple files, just list them on the command line using a space to separate them. For example:

    vbc sample1.vb sample2.vb /t:winexe /r:system.windows.forms.dll 

Since sample1.vb is the first file listed, and since a specific output filename is not indicated, the compiler will generate a Windows executable named sample1.exe.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net