Simple .NET Core application using VB.NET

.NET Core 2 Preview 1 bits bring us support for VB.NET on .NET Core. Although tooling for web applications is not ready yet we can start with console applications and also some web applications like I will show in some of my later posts. Visual Studio 2017 Preview 2 is needed to try VB.NET out on .NET Core. This blog post is short demo about how to build simple utility application on .NET Core 2 Preview 1 using VB.NET.

What about ASP.NET Core and VB.NET? It’s coming, I’m sure. I was able to write Pages and MVC applications on VB.NET but failed to get views working with tag helpers. Web based API-s that doesn’t require views can be written on VB.NET already today.

Let’s write simple VB.NET application that runs on .NET Core. We start with creating new application.

.NET Core Console App on VB.NET

As a result new application with Program.vb file is created. By deafult Program.vb contains just Main sub for application startup.

The application will download robots.txt file and save it to disk. So, it’s simple utility application. Code is here.


Imports System.IO
Imports System.Net

Module Program
    Sub Main(args As String())
        Dim request As WebRequest

        request = HttpWebRequest.CreateHttp("http://www.w3.org/robots.txt")
        Using response As WebResponse = request.GetResponse(),
              file As FileStream = New FileStream("robots.txt", FileMode.CreateNew)

            response.GetResponseStream().CopyTo(file)
        End Using

        Console.WriteLine("Press Enter to continue ...")
        Console.ReadLine()
    End Sub
End Module

After running the project there is robots.txt file in project root folder.

Wrapping up

.NET Core 2 enables VB.NET developers to join .NET Core world. VB.NET is here and will be fully supported .NET Core family member from .NET Core 2. It’s possible to write utility applications on .NET Core using VB.NET already today. Also writing web applications is supported but tooling is not ready yet. While VB.NET is getting fully to .NET Core it’s good idea for VB.NET developers to start playing with it already today.



See also

Leave a Reply

Your email address will not be published. Required fields are marked *