Visual Basic .NET is compiled by the Roslyn compiler, which Visual Studio and the .NET SDK both use. The command-line form is vbc; most projects go through dotnet or MSBuild and a .vbproj file. The classic languages have their own environments.
The compiler: vbc
The options below are those printed by vbc -help of the compiler that ships with the .NET 10 SDK (version 5.9.0 of Roslyn); options start with - or /.
| Group | Options |
|---|---|
| output | -out:file, -target:exe|winexe|library|module|appcontainerexe|winmdobj, -doc[+|-] and -doc:file (the XML documentation from ''' comments), -refout:file |
| input | -reference:files (-r), -addmodule, -link, -recurse:wildcard, -analyzer, -additionalfile, -libpath |
| language | -define:symbols (name=value, comma-separated: the constants of #If), -imports:namespaces, -langversion: (default, latest, 9, 10, 11, 12, 14, 15, 15.3, 15.5, 16, 16.9, 17.13; -langversion:? lists them, and the SDK’s compiler reports 17.13 as the default), -optionexplicit[+|-], -optioninfer[+|-], -optionstrict[+|-] and -optionstrict:custom, -optioncompare:binary|text (binary is the default), -rootnamespace:name, -main:class (the class or module with Sub Main) |
| code generation | -optimize[+|-], -removeintchecks[+|-] (removes the integer overflow checks; off by default), -debug[+|-] and -debug:full|pdbonly|portable|embedded, -deterministic, -platform:x86|x64|Itanium|arm|arm64|AnyCPU32BitPreferred|anycpu, -codepage:number (the encoding of the source files), -checksumalgorithm |
| warnings | -nowarn[:numbers], -warnaserror[+|-][:numbers], -ruleset:file, -errorlog:file |
| resources | -resource, -linkresource, -win32icon, -win32manifest, -win32resource, -nowin32manifest |
| signing and other | -keyfile, -keycontainer, -delaysign, -publicsign, -nologo, -quiet, -verbose, -parallel, -version, -noconfig, -nostdlib, -sourcelink, -pathmap |
The project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>VbCheck</RootNamespace>
<StartupObject>VbCheck.Program</StartupObject>
<OptionStrict>On</OptionStrict>
<OptionInfer>On</OptionInfer>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>
.vbproj (the one used to compile the examples of these pages). The project is XML, not Visual Basic.A .vbproj is MSBuild XML. In the SDK style the source files are all **/*.vb below the project folder; the old style (Visual Studio 2008 to 2015 and .NET Framework projects) lists every file in <Compile Include="…"> items. The Visual Basic properties are RootNamespace, OptionExplicit, OptionStrict, OptionInfer, OptionCompare (Binary or Text), LangVersion, MyType (the type of project for My: Console, Windows, WindowsForms, WindowsFormsWithCustomSubMain, Web, Custom or Empty), StartupObject, DefineConstants, NoWarn, WarningsAsErrors and <Import Include="Namespace" /> items for project-wide Imports. The commands dotnet new console -lang VB, dotnet build and dotnet run create, build and run one; the SDK writes obj/…/*.AssemblyInfo.vb for the assembly attributes (see file structure). A solution (.sln) groups projects.
Environments and other compilers
- Visual Studio creates and debugs Visual Basic .NET projects, with Windows Forms, WPF, class library, console and ASP.NET project types (Windows only).
- The .NET SDK builds Visual Basic on Windows, macOS and Linux; Visual Studio Code and other editors use the Roslyn language services.
- Visual Basic 6 (
VB6.EXE) opens.vbpand.vbgfiles and builds them to EXE, DLL and OCX with its own compiler (vb6 /make project.vbp, from memory). Visual Studio .NET to 2008 had an upgrade wizard for VB6 projects; later versions have none. - VBA lives in the Visual Basic Editor of Office (Alt+F11): it exports and imports
.bas,.clsand.frmfiles, and stores the code inside the document otherwise. - Windows Script Host runs
.vbsfiles (cscript,wscript); HTML Applications run.htafiles. - Other implementations: twinBASIC compiles Visual Basic 6 and VBA code natively; the Mono project had a
vbnccompiler for the older language versions (from memory); the Roslyn analyzers and the language server support editing and refactoring.
Not described
Known, not yet covered
- Reference: the MSBuild properties and items of Visual Basic projects in full, the old-style project format, Visual Studio’s project templates, the VB6 compiler options and command line, the VBA project storage formats inside Office files, and the Visual Studio language services are not described;
.vbprojfiles are XML and belong to a later item on this site.
See also
- Versions and history – the language versions
-langversionaccepts - File structure and options – the Option statements the compiler options set