VB.NET 1.1 Tutorial - Command Line Compiling


To access the command line in windows, install the CommandPromptHere Powertoy that can be downloaded here. Once downloaded, right-click on the file and choose Install.

Once installed you should be able to right-click on a directory in windows explorer, this should give you a dialog similar to the one shown below. Choose "Command Prompt Here" to open the DOS enviroment at this location.

Console Applications

To compile a console application type the following at the command prompt:

vbc /r:system.dll file.vb

Where file is the name of your .vb file. Alternatively if you are compiling a project with more than one .vb file, then you would type the following at the command prompt:

vbc /r:system.dll *.vb

Alternatively, you can add the target switch into the command line which gives:

vbc /target:exe /r:system.dll *.vb

Compiler Option /r:

This is actually the compiler option /reference: and is used to include the type information in the specified assemblies during compilation. For each Imports statement, we need to include the appropriate dll references. So to compile a simple console application, we include the system.dll in the reference option.

Windows Applications

When compiling a windows application such as that of a winform, if we only type the vbc /t:exe ... as in the console application we will get a console application behind our form when we run the program as per the following picture.

In order to make the console application go away, we add the switch /target:winexe. If you're using VS.NET this should happen automatically when you create a Windows Application project.

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

Note the include of the system.windows.forms.dll in the reference option. Depending on what you are using in your winform, other dll files will also need including in the reference ooption.

Similar to the console application, if we are compiling a windows application with more than one .vb file, then we use the wildcard (*) instead of file.

Debugging

If we leave the console window behind the form when we compile our program, we can use it as a debug window, by sending Console.WriteLine() messages to it during execution.


What Next?

If you want to know more, have a look at the compiler options.

Return to the Tutorial Contents.