Ever needed to compile some .vb code? Here's how I did it today.
Given a text file called Helloworld.vb with the following content...
Imports System
Module HelloWorld
Sub Main(args As String())
Console.WriteLine("Hello World!")
End Sub
End Module
You can create this file on any path you see fit with any editor Notepad, Notepad++, Atom, VSCode, pick one. : )
For this example I'm using Visual Studio 2022, which look like this...
Visual Studio defaults to creating content in your %userprofile%\source\repos dir. On creating the VB Console project HelloWorld, it saved the source as %userprofile%\source\repos\HelloWorld\HelloWorld\HelloWorld.vb.
Make sure the latest vbc.exe is on the path.
On My Windows 11 PC it existed in...
C:\Windows\Microsoft.NET\Framework64\v4.0.30319.
With Visual Studio Community Edition 2022, I found it located in C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn.
Make sure to search and use the on you want to work with.
Start cmd
Issue commands to go to the directory with your source .vb file
>c:
>cd %userprofile%\source\repos\HelloWorld\HelloWorld
>dir
You directory may look like the following...Visual Studio will also create other legacy elements for managing the code within its environment. For our purposes they are not needed and can be ignored.
Issue the follow commands
>vbc HelloWorld.vb
** Vbc (the older .Net version) will tell you that there is a better method to use called Roslyn which comes automatically with Visual Studio.
>dir
There's our .exe file! :)
Run HelloWorld
From the cmd prompt issue the command "helloworld"
It works! : )
You now have a .exe you can use anywhere.